#include "TutorialPlayState.h"
#include "BaseMessage.h"
#include "Messages\CreateCharacterMessage.h"
#include "Messages\WinTileEventMessage.h"
#include "MessagingSystem.h"
#include "SGD Wrappers\SGD_Math.h"
#include <random>
#include <ctime>
#include "AnimationManager.h"
#include "ParticleManager.h"
#include "tinyxml\tinyxml.h"
#include "Messages\CreateItemMessage.h"
#include <iostream>
#include "GamePlayState.h"
#include "AIManager.h"

#define MAX_MENU_COMMANDS 9

TutorialPlayState* TutorialPlayState::pInstance = nullptr;

TutorialPlayState::TutorialPlayState(void)
{
	declineID			= -1;
	acceptID			= -1;
	errorID				= -1;
	moveID				= -1;
	BGMID				= -1;
	CursorID			= -1;
	FontID				= -1;
	BackgroundID		= -1;
	PanelID				= -1;
	selectID			= -1;
	rhurtID				= -1;
	whurtID				= -1;
	khurtID				= -1;
	ahurtID				= -1;
	boltID				= -1;
	fireID				= -1;
	waterID				= -1;
	boingID				= -1;
	thudID				= -1;
	swingID				= -1;
	throwID				= -1;
	splashID			= -1;
	crackerID			= -1;
	tennisID			= -1;
	TennisballID		= -1;
	PlungerID			= -1;
	fireCrackerID		= -1;
	WaterBalloonID		= -1;
	FadeImg				= -1;
	Explosion			= -1;
	currentMsg			= -1;
	AtkTypeStorage		= -1;
	tempAtk				= -1;
	tempStm				= -1;
	tempDef				= -1;
	tempAgi				= -1;
	tempSpd				= -1;
	tempHP				= -1;
	tempMP				= -1;
	tempLvl				= -1;
	gameWonTimer		= 0.0f;
	gameWon				= false;
	
	CurAttacker			= nullptr;
	CurDefender			= nullptr;
	Throw				= true;
	SpellHit			= false;
	playVoice			= false;
	fbHurt				= true;
	Paused				= false;
	Resume				= true;
	Movement			= false;
	Command				= false;
	Attack				= false;
	ItemMenu			= false;
	StatsMenu			= false;
	ItemChoice			= -1;
	CmndChoice			= -1;
	MenuChoice			= -1;
	gameWon				= false;
	gameWonTimer		= -1;
	HPotions			= -1;
	MPotions			= -1;
	Inhalers			= -1;
	cursorX				= -1;
	cursorY				= -1;
	currentMsg			= -1;
	SizeOfParty			= -1;
	Shotspeed			= 0.0f;
	Shotspeed2			= 0.0f;
	checktimer			= 0.0f;
	SelectingaTile		= false;
	tutMove				= false;
	tutAttack			= false;
	tutItem				= false;
	tutWeather			= false;
	tutTiles			= false;
	tutCharExplain		= false;
	tutSpawnPoint		= false;
	tutSpecialWin		= false;
	tutControls			= false;
	tutAbility			= false;
	tutMenu				= false;
	convo				= false;
	abilityMenu			= false;
	abilityTargeting	= false;
	prebattle			= false;
	abilitySelection	= 0;
	DiceShown			= false;
	DiceRolled			= false;
	gameGrid			= nullptr;
	WS					= nullptr;
	MS					= nullptr;
	leftSideSelecting	= false;
	arcadeEnter			= false;
	arcadeEscape		= false;
	arcadeUp			= false;
	arcadeDown			= false;
	arcadeLeft			= false;
	arcadeRight			= false;
	arcadeBackspace		= false;
	arcadeShift			= false;
	arcadePlus			= false;
	arcadeMinus			= false;
	arcadeP				= false;
	Viewing				= nullptr;
	fadeWindow.left		= 0;
	fadeWindow.top		= 0;
	fadeWindow.right	= 0;
	fadeWindow.bottom	= 0;
	preLeftSelection	= -1;

	//tutConvo.clear();

}


TutorialPlayState::~TutorialPlayState(void)
{

	tutConvo.clear();
}

TutorialPlayState* TutorialPlayState::GetInstance(void)
{
	if(pInstance == nullptr)
		pInstance = new TutorialPlayState();

	return pInstance;
}

void TutorialPlayState::DeleteInstance()
{
	if(pInstance != nullptr)
	{
		delete pInstance;
		pInstance = nullptr;
	}
}

void TutorialPlayState::Enter(void)
{
	// Seed random number generator
	srand((unsigned int)time(0));

	// Set variables
	Paused = false;
	Resume = true;
	Movement = false;
	Command = false;
	Attack = false;
	ItemMenu = false;
	StatsMenu = false;
	ItemChoice = 0;
	CmndChoice = 0;
	MenuChoice = 0;
	gameWon = false;
	gameWonTimer = 0;
	HPotions = 0;
	MPotions = 0;
	Inhalers = 0;
	cursorX = 0;
	cursorY = 0;
	currentMsg = 0;
	tutMove = false;
	tutAttack = false;
	tutItem = false;
	tutWeather = false;
	tutTiles = false;
	tutCharExplain = false;
	tutSpawnPoint = false;
	tutSpecialWin = false;
	tutControls = false;
	tutAbility = false;
	tutMenu = true;
	convo = true;
	abilityMenu = false;
	abilityTargeting = false;
	abilitySelection = 0;
	bool DiceShown = false;
	bool DiceRolled = false;
	float DShownTime = 0.0f;
	float DiceTime1 = 0.0f;
	float DiceTime2 = 0.0f;
	SizeOfParty = 0;
	AtkTypeStorage = -1;
	Shotspeed = 0.0f;
	Shotspeed2 = 0.0f;
	Modifier = 0.0f;

	PlungerID			= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/plunger.png"));
	fireCrackerID		= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/firecracker.png"));
	WaterBalloonID		= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/WaterBalloon.png"));
	FadeImg				= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/FadeWindow.png"));

	declineID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_InGame_Decline.wav"));
	acceptID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_InGame_Accept.wav"));
	errorID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_InGame_Error.wav"));
	moveID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_Main_Move.wav"));
	rhurtID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Rogue_Damage.wav"));
	whurtID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Damage.wav"));
	khurtID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Knight_Damage.wav"));
	ahurtID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Archer_Damage.wav"));
	TennisballID		= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/TennisBall.png"));
	boltID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_LightningBolt.wav"));
	fireID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Fireball.wav"));
	waterID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Tsunami.wav"));
	boingID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Bow_Boing.wav"));
	thudID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Cardboard_Impact.wav"));
	swingID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Cardboard_Swish.wav"));
	throwID				= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Throw_Item.wav"));
	splashID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/WaterBalloon.wav"));
	crackerID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/FireCracker.wav"));
	tennisID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/TennisBall.wav"));
	Explosion			= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Boom.png"));

	fadeWindow.left		= 0;
	fadeWindow.top		= 0;
	fadeWindow.right	= Game::GetInstance()->GetWinWidth();
	fadeWindow.bottom	= Game::GetInstance()->GetWinHeight();

	GamePlayState::GetInstance()->SetFadeWindow(fadeWindow);
	GamePlayState::GetInstance()->SetFadeWindowImage(FadeImg);
	GamePlayState::GetInstance()->SetAtckSound(swingID);
	GamePlayState::GetInstance()->SetLBoltHit(tennisID);
	GamePlayState::GetInstance()->SetLBoltImg(TennisballID);
	GamePlayState::GetInstance()->SetHitSound(thudID);
	GamePlayState::GetInstance()->SetExplosionImg(Explosion);
	GamePlayState::GetInstance()->SetThrowID(throwID);
	GamePlayState::GetInstance()->SetModifier(0.0f);
	GamePlayState::GetInstance()->SetKhurtId(khurtID);
	GamePlayState::GetInstance()->SetBoltID(boltID);

	for(unsigned int i = 0; i < 8;i++)
	{
		BaseCharacter * c;
	
		switch((i/2)+1)
		{
		case KNIGHT:
			{
				c = new Knight(true);
				break;
			}
		case ARCHER:
			{
				c = new Archer(true);
				break;
			}
		case ROGUE:
			{
				c = new Rogue(true);
				break;
			}
		case WIZARD:
			{
				c = new Wizard(true);
				break;
			}
		case BLACK_KNIGHT:
			{
				c = new BlackKnight(true);
				break;
			}
	
		};
		//SizeOfParty++;
		selectFrom.push_back(c);
		//c->Release();
	}
	selected.clear();
	leftSideSelecting = true;

	preLeftSelection = 0;
	preRightSelection = 0;
	prebattle = false;
	SelectingaTile = false;
	SelectingCount = 0;


	// Load Assets
	BGMID		 = CSGD_XAudio2::GetInstance()->MusicLoadSong(_T("resource/Tutorial.xwm"));
	CursorID	 = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/SGD_MenuCursor.png"));
	FontID		 = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/LARPFont.png"),D3DCOLOR_XRGB(0,0,0));
	BackgroundID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/optionsmenu.png"));
	//tileBmpID	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/testtileset.bmp"));
	Font.Initialize(FontID,"LARPFont.fnt");

	GamePlayState::GetInstance()->SetFontID(FontID);
	GamePlayState::GetInstance()->SetFont(Font);

	// Set up sound
	CSGD_XAudio2::GetInstance()->SFXSetMasterVolume(Game::GetInstance()->SfxVol);
	CSGD_XAudio2::GetInstance()->MusicSetMasterVolume(Game::GetInstance()->BgmVol);
	CSGD_XAudio2::GetInstance()->MusicSetSongPan(BGMID, Game::GetInstance()->Pan);
	CSGD_XAudio2::GetInstance()->MusicPlaySong(BGMID, true);

	//load Dice Images
	DiceImages.push_back(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/DiceSheet.png")));
	DiceImages.push_back(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/CJDiceSheet.bmp")));

	GamePlayState::GetInstance()->SetDiceID(DiceImages);
	GamePlayState::GetInstance()->SetDiceTime1(0.0f);
	GamePlayState::GetInstance()->SetDiceTime2(0.0f);
	GamePlayState::GetInstance()->SetDShownTime(0.0f);

	//Battle window stuff
	FadeWindowImg = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/FadeWindow.png"));

	// Set up AnimationManager 
	myManager = Game::GetInstance()->GetAnimManager();
	GamePlayState::GetInstance()->SetAniManager(myManager);
	
	// Init message system
	MS = MessagingSystem::GetInstance();
	MS->InitMessageSystem(&TutorialPlayState::MessageProc);

	// init tile manager
	this->gameGrid = TileManager::GetInstance();
	gameGrid->CreateGrid("resource/TestMap2.xml");
	

	size_t size;
	TCHAR buffer[128] = {};
	mbstowcs_s(&size,buffer,128,(gameGrid->GetTileSetFile()),128);

	tileBmpID = CSGD_TextureManager::GetInstance()->LoadTexture(buffer);
	gameGrid->SetTileBmpID(this->tileBmpID);

	//ParticleManager
	ParticleManager::GetInstance()->Load("Rain.xml");
	ParticleManager::GetInstance()->Load("Snow.xml");
	ParticleManager::GetInstance()->Load("FireBall.xml");
	ParticleManager::GetInstance()->Load("TsunamiRight.xml");
	ParticleManager::GetInstance()->Load("Allergies.xml");

	keys.push_back("Rain.xml");
	keys.push_back("Snow.xml");
	keys.push_back("FireBall.xml");
	keys.push_back("TsunamiRight.xml");
	keys.push_back("Allergies.xml");

	myManager->LoadAnimations("animations.xml");

	WS = WeatherSystem::GetInstance();

	PanelID	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/HUD.png"));
	selectID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/SelectionBox.png"));

	// Create Stuff
	CreateItemMessage* pMsg2 = new CreateItemMessage(HPOTION);
	CreateItemMessage* pMsg3 = new CreateItemMessage(HPOTION);
	CreateItemMessage* pMsg4 = new CreateItemMessage(MPOTION);
	MS->SendMsg(pMsg2);
	MS->SendMsg(pMsg3);
	MS->SendMsg(pMsg4);
	HPotions = 2;
	MPotions = 1;

	arcadeEnter = false;
	arcadeEscape = false;
	arcadeUp = false;
	arcadeDown = false;
	arcadeLeft = false;
	arcadeRight = false;
	arcadeBackspace = false;
	arcadeShift = false;
	arcadePlus = false;
	arcadeMinus = false;
	arcadeP = false;

}

bool TutorialPlayState::Input(void)
{

	ArcadeInput();

	if(tutMenu)
	{
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

			if(MenuChoice > 0)
			MenuChoice -=1;

			else
				MenuChoice = MAX_MENU_COMMANDS;
		}

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

			if(MenuChoice < MAX_MENU_COMMANDS)
			MenuChoice +=1;
		
			else
				MenuChoice = 0;
		}

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
		{

			switch(MenuChoice)
			{
			case 0:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutMove = true;
					tutMenu = false;
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}
				

			case 1:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutAttack = true;
					tutMenu = false;
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}

			case 2:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutItem = true;
					tutMenu = false;
					
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}

			case 3:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutAbility = true;
					tutMenu = false;
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}

			case 4:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutTiles = true;
					tutMenu = false;
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}

			case 5:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutSpecialWin = true;
					tutMenu = false;
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}

			case 6:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					tutMenu = false;
					tutWeather = true;
					WS->ChangeWeather("Sun.xml");
					LoadFile();

					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}

					Characters.clear();
					CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
					CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
					MS->SendMsg(pMsg);
					MS->SendMsg(pMsg1);
					break;
				}
			

			case 7:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}
					Characters.clear();

					CreateCharacterMessage* pMsg13 = new CreateCharacterMessage(false, KNIGHT,		3, 1);
					CreateCharacterMessage* pMsg14 = new CreateCharacterMessage(false, ROGUE,		3, 2);
					CreateCharacterMessage* pMsg15 = new CreateCharacterMessage(false, ARCHER,		3, 3);
					CreateCharacterMessage* pMsg16 = new CreateCharacterMessage(false, WIZARD,		3, 4);
					CreateCharacterMessage* pMsg17 = new CreateCharacterMessage(false, BLACK_KNIGHT,3, 5);
	
					MS->SendMsg(pMsg13);
					MS->SendMsg(pMsg14);
					MS->SendMsg(pMsg15);
					MS->SendMsg(pMsg16);
					MS->SendMsg(pMsg17); 
					prebattle = true;
					tutMenu = false;
					tutSpawnPoint = true;

					LoadFile();	
					break;
				}
				
			case 8:
				{
					currentMsg = 0;
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					if(Characters.size() > 0)
					{
						for(unsigned int i = 0; i < Characters.size(); ++i)
							delete Characters[i];
					}
					Characters.clear();
					CreateCharacterMessage* pMsg13 = new CreateCharacterMessage(false, KNIGHT,		1, 3);
					CreateCharacterMessage* pMsg14 = new CreateCharacterMessage(false, ROGUE,		2, 3);
					CreateCharacterMessage* pMsg15 = new CreateCharacterMessage(false, WIZARD,		3, 3);
					CreateCharacterMessage* pMsg16 = new CreateCharacterMessage(false, ARCHER,		4, 3);
					CreateCharacterMessage* pMsg17 = new CreateCharacterMessage(false, BLACK_KNIGHT,5, 3);

					MS->SendMsg(pMsg13);
					MS->SendMsg(pMsg14);
					MS->SendMsg(pMsg15);
					MS->SendMsg(pMsg16);
					MS->SendMsg(pMsg17);

					tutCharExplain = true;
					tutMenu = false;
					LoadFile();
				}
				break;

			case 9:
				CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
				tutMenu = false;
				Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
				break;
			};		
		}
	}

	else
	{
		// Pause/Unpause
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_ESCAPE)||arcadeEscape)
			Paused = !Paused;
		// Pause Menu Input
		if(!Paused)
		{

			TileManager * tm = TileManager::GetInstance();

			bool cursorMoved = false;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//************************************************************Begin Movement Tutorial********************************************************************************************************//
			if(tutMove)
			{
				//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				//{
				//	cout << currentMsg <<' ';
				//	cout << tutConvo[currentMsg].c_str() << '\n';
				//}

				if(convo)
				{
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

						currentMsg++;

						if( currentMsg == 10 || currentMsg == 14 )
							convo = false;

						if(currentMsg == 17)
						{
							Reset();
						}
					}
				}

				else
				{
				
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
					if(!Command && !ItemMenu)
					{
						cursorMoved = true;
						cursorY--;
						if(cursorY < 0)
							cursorY = 0;
					}
					else if(Command)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice > 0)
							CmndChoice -= 1;
						else
							CmndChoice = 5;
					}
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
						if(!Command && !ItemMenu)
						{
							cursorMoved = true;
							cursorY++;
							if(cursorY >= tm->GetSizeY())
								cursorY = tm->GetSizeY() -1;
						}
						
						else if(Command)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

							if(CmndChoice < 5)
								CmndChoice += 1;
							else
								CmndChoice = 0;
						}
						
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
					{
						cursorMoved = true;
						cursorX--;
						if(cursorX < 0)
							cursorX = 0;
					}

					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
					{
						cursorMoved = true;
						cursorX++;
						if(cursorX >= tm->GetSizeX())
							cursorX = tm->GetSizeX()-1;
					}


					if(cursorMoved)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						RECT cursorRect;
						cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
						cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
						cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
						cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

						if(cursorRect.left < 0)
						{
							tm->SetPosX(-cursorX*tm->GetTileSizeX());
						}
						if(cursorRect.right > Game::GetInstance()->GetWinWidth())
						{
							tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
						}
						if(cursorRect.top < 0)
						{
							tm->SetPosY(-cursorY*tm->GetTileSizeY());
						}
						if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
						{
							tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
						}
					}

					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
					{

						if(!Movement && !Attack && !Command && !ItemMenu)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

							activeTile = tm->ReturnHilightedTile(1);
							if(activeTile->GetCharacter() != nullptr && activeTile->GetCharacter()->IsPlayer())
							{
								Command = true;
								convo = true;
								currentMsg++;
							}
						}
						else if(Movement)
						{
							Tile * selected = tm->ReturnHilightedTile(1);
							Tile * start = Characters[0]->GetTile();
							if(selected->GetCharacter() == nullptr)
							{
								if(activeTile->GetCharacter()->Move(selected, 1))
								{
									if(selected->GetX() == 1 && selected->GetY() == 1)
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

										convo = true;
										currentMsg++;

										Movement = false;
										selected->GetCharacter()->SetMoved(false);
									}
									else
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);

										activeTile = start;
										selected->GetCharacter()->SetMoved(false);
										selected->GetCharacter()->Move(start, 1);
										selected = activeTile;
										selected->GetCharacter()->SetMoved(false);
										this->HighlightMove();
									
									}
								}
								
							}
						}

						else if(Command && !Attack && !Movement && !ItemMenu)
						{
							
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

							switch(CmndChoice)
							{
							case 0:
								{
									Movement = true;
									this->HighlightMove();
									break;
								}

							case 1:
								{
									return true;
									break;
								}

							case 2:
								return true;
								break;

							case 3:
								return true;
								break;

							case 4:
								return true;
									break;
								

							case 5:
								break;
							};

							Command = false;
						}

					}
				}
			}
//**************************************************************End Movement Tutorial********************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************Begin Item Tutorial**********************************************************************************************************//

		if(tutItem)
		{
			if(currentMsg == 0)
			Characters[0]->SetHP(10);

			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

					currentMsg++;

					if( currentMsg == 7 || currentMsg == 9 )
							convo = false;

						if(currentMsg == 14)
						{
							Reset();
						}
				}
			}

			else
			{

				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
					if(!Command && !ItemMenu)
					{
						cursorMoved = true;
						cursorY--;
						if(cursorY < 0)
							cursorY = 0;
					}
					else if(Command && !ItemMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice > 0)
							CmndChoice -= 1;
						else
							CmndChoice = 5;
					}
					else if(ItemMenu && !Command)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						if(ItemChoice > 0)
							ItemChoice -= 1;
						else
							ItemChoice = 3;
					}
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
					if(!Command && !ItemMenu)
					{
						cursorMoved = true;
						cursorY++;
						if(cursorY >= tm->GetSizeY())
							cursorY = tm->GetSizeY() -1;
					}
						//tm->SetPosY(tm->GetPosY()- tm->GetTileSizeY());// * tm->GetScale()));
					else if(Command && !ItemMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice < 5)
							CmndChoice += 1;
						else
							CmndChoice = 0;
					}
					else if(ItemMenu && !Command)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						if(ItemChoice < 3)
							ItemChoice += 1;
						else
							ItemChoice = 0;
					}
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
				{
					cursorMoved = true;
					cursorX--;
					if(cursorX < 0)
						cursorX = 0;
				}

				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
				{
					cursorMoved = true;
					cursorX++;
					if(cursorX >= tm->GetSizeX())
						cursorX = tm->GetSizeX()-1;
				}

				if(cursorMoved)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
					RECT cursorRect;
					cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
					cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
					cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
					cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

					if(cursorRect.left < 0)
					{
						tm->SetPosX(-cursorX*tm->GetTileSizeX());
					}
					if(cursorRect.right > Game::GetInstance()->GetWinWidth())
					{
						tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
					}
					if(cursorRect.top < 0)
					{
						tm->SetPosY(-cursorY*tm->GetTileSizeY());
					}
					if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
					{
						tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
					}
				}

				

				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					if(!Movement && !Attack && !Command && !ItemMenu)
					{
						activeTile = tm->ReturnHilightedTile(1);
						if(activeTile->GetCharacter() != nullptr && activeTile->GetCharacter()->IsPlayer())
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							Command = true;
							convo = true;
							currentMsg++;
							
						}
					}
					/*else if(Movement && !Attack && !Command && !ItemMenu)
					{
						Tile * selected = tm->ReturnHilightedTile(1);
						if(selected->GetCharacter() == nullptr)
							if(activeTile->GetCharacter()->Move(selected))
							{
								Movement = false;
								selected->GetCharacter()->SetMoved(false);
							}
					}*/
					else if(Command && !Attack && !Movement && !ItemMenu)
					{
						switch(CmndChoice)
						{
						case 0:
							{
								//Movement = true;
								return true;
								break;
							}

						case 1:
							{
								return true;
								break;
							}

						case 2:
							return true;
							break;

						case 3:
							return true;
							break;

						case 4:
							{
								CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

								ItemMenu = true;
								break;
							}

						case 5:
							break;
						};
						Command = false;
					}
					else if(ItemMenu && !Command && !Attack && !Movement)
					{
						//convo = true;
						//currentMsg++;
						switch(ItemChoice)
						{
						case 0:
							{
								if(HPotions != 0)
								{
									vector<Item*>::iterator iter = Inventory.begin();
									for( ; iter != Inventory.end(); ++iter)
									{
										if((*iter)->GetID() == HPOTION)
										{
											if(activeTile->GetCharacter()->UseItem(*iter))
											{
												CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
												convo = true;
												currentMsg++;

												HPotions -= 1;
												delete(*iter);
												Inventory.erase(iter);
												ItemMenu = false;
												
												
												break;
											}

											else
											{
												CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
												break;
											}
										}
									}
								}
								else
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									break;
							}

						case 1:
							{
								if(MPotions != 0)
								{
									vector<Item*>::iterator iter = Inventory.begin();
									for( ; iter != Inventory.end(); ++iter)
									{
										if((*iter)->GetID() == MPOTION)
										{
											if(activeTile->GetCharacter()->UseItem(*iter))
											{
												CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

												MPotions -= 1;
												delete(*iter);
												Inventory.erase(iter);
												ItemMenu = false;
												break;
											}

											else
											{
												CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
												break;
											}
										}
									}
								}
								else
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									break;
							}

						case 2:
							{
								if(Inhalers != 0)
								{
									vector<Item*>::iterator iter = Inventory.begin();
									for( ; iter != Inventory.end(); ++iter)
									{
										if((*iter)->GetID() == INHALER)
										{
											if(activeTile->GetCharacter()->UseItem(*iter))
											{
												CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

												Inhalers -= 1;
												delete(*iter);
												Inventory.erase(iter);
												ItemMenu = false;
												break;
											}

											else
											{
												CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
												break;
											}
										}
									}
								}
								else
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									break;
							}

						case 3:
							{
								CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
								Command = true;
								ItemMenu = false;
							}
						};
					}
				}
			}

		}
//****************************************************************End Item Tutorial**********************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************Begin Attack Tutorial********************************************************************************************************//

		if(tutAttack)
		{

			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

					currentMsg++;
			
					if( currentMsg == 4 || currentMsg == 7 )
							convo = false;
			
						if(currentMsg == 13)
						{
							Reset();
						}
				}
			}
			
			else
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
					if(!Command && !ItemMenu)
					{
						cursorMoved = true;
						cursorY--;
						if(cursorY < 0)
							cursorY = 0;
					}
					else if(Command && !ItemMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice > 0)
							CmndChoice -= 1;
						else
							CmndChoice = 5;
					}
					/*else if(ItemMenu && !Command)
					{
						if(ItemChoice > 0)
							ItemChoice -= 1;
						else
							ItemChoice = 3;
					}*/
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
					if(!Command && !ItemMenu)
					{
						cursorMoved = true;
						cursorY++;
						if(cursorY >= tm->GetSizeY())
							cursorY = tm->GetSizeY() -1;
					}
						//tm->SetPosY(tm->GetPosY()- tm->GetTileSizeY());// * tm->GetScale()));
					else if(Command && !ItemMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice < 5)
							CmndChoice += 1;
						else
							CmndChoice = 0;
					}
					/*else if(ItemMenu && !Command)
					{
						if(ItemChoice < 3)
							ItemChoice += 1;
						else
							ItemChoice = 0;
					}*/
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
				{
					cursorMoved = true;
					cursorX--;
					if(cursorX < 0)
						cursorX = 0;
				}
					//tm->SetPosX(tm->GetPosX()+ tm->GetTileSizeX());// * tm->GetScale()));
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
				{
					cursorMoved = true;
					cursorX++;
					if(cursorX >= tm->GetSizeX())
						cursorX = tm->GetSizeX()-1;
				}
					//tm->SetPosX(tm->GetPosX()- tm->GetTileSizeX());// * tm->GetScale()));
				
				if(cursorMoved)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
					RECT cursorRect;
					cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
					cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
					cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
					cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

					if(cursorRect.left < 0)
					{
						tm->SetPosX(-cursorX*tm->GetTileSizeX());
					}
					if(cursorRect.right > Game::GetInstance()->GetWinWidth())
					{
						tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
					}
					if(cursorRect.top < 0)
					{
						tm->SetPosY(-cursorY*tm->GetTileSizeY());
					}
					if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
					{
						tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
					}
				}
				
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					if(!Movement && !Attack && !Command && !ItemMenu)
					{
						activeTile = tm->ReturnHilightedTile(1);
						if(activeTile->GetCharacter() != nullptr && activeTile->GetCharacter()->IsPlayer())
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							Command = true;
						}
					}
					else if(Movement && !Attack && !Command && !ItemMenu)
					{
						Tile * selected = tm->ReturnHilightedTile(1);
						Tile * start = Characters[0]->GetTile();

						if(selected->GetCharacter() == nullptr)
							if(activeTile->GetCharacter()->Move(selected, 1))
							{
								if((selected->GetX() == 2 && selected->GetY() == 2))
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
									convo = true;
									currentMsg++;
									
									Movement = false;
									selected->GetCharacter()->SetMoved(false);
									
								}

								else
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									activeTile = start;
									selected->GetCharacter()->SetMoved(false);
									selected->GetCharacter()->Move(start, 1);
									selected = activeTile;
									selected->GetCharacter()->SetMoved(false);
									this->HighlightMove();
								}
							}		
							
					}
					else if(Attack && !Movement && !Command && !ItemMenu)
					{
						Tile * selected = tm->ReturnHilightedTile(1);
						if(selected->GetCharacter() != nullptr && selected->GetCharacter()->IsPlayer() == false)
							if(currentMsg != 4)
							if(activeTile->GetCharacter()->Attack(selected, 1))
							{
								//GamePlayState::GetInstance()->SetCurAttacker(activeTile->GetCharacter());
								//GamePlayState::GetInstance()->SetCurDefender(selected->GetCharacter());

								CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

								//convo = true;
								//currentMsg++;

								cursorMoved = true;
								cursorY++;
								Attack = false;
								activeTile->GetCharacter()->SetActed(false);
								tm->ResetHighlights();
							}

							else
								CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					}
					else if(Command && !Attack && !Movement && !ItemMenu)
					{
						switch(CmndChoice)
						{
						case 0:
							{
								if(currentMsg != 7)
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
									Movement = true;
									this->HighlightMove();
								}
								break;
							}
				
						case 1:
							{
								CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
								Attack = true;
								this->HighlightAction(true,activeTile->GetCharacter()->GetRng());
								break;
							}
				
						case 2:
							return true;
							break;
				
						case 3:
							return true;
							break;
				
						case 4:
							{
								return true;
								break;
							}
				
						case 5:
							break;
						};
						Command = false;
					}
					
				}
			}
			

		}

//***************************************************************End Attack Tutorial*********************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//************************************************************Begin Ability Tutorial********************************************************************************************************//
		if(tutAbility)
		{
			Characters[0]->SetMP(10);
			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

					currentMsg++;
			
					if( currentMsg == 3 || currentMsg == 7 )
							convo = false;
			
						if(currentMsg == 11)
						{
							Reset();
						}
				}
			}
			
			else
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
					if(!Command && !ItemMenu && !abilityMenu)
					{
						cursorMoved = true;
						cursorY--;
						if(cursorY < 0)
							cursorY = 0;
					}
					else if(Command && !ItemMenu && !abilityMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice > 0)
							CmndChoice -= 1;
						else
							CmndChoice = 5;
					}
					/*else if(ItemMenu && !Command)
					{
						if(ItemChoice > 0)
							ItemChoice -= 1;
						else
							ItemChoice = 3;
					}*/
					else if(abilityMenu && !Command && !ItemMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(tm->ReturnHilightedTile(1)->GetCharacter()->GetType() != WIZARD)
						{
							if(abilitySelection >0)
								abilitySelection--;
							else
								abilitySelection = 3;
						}
						else
						{
							if(abilitySelection >0)
								abilitySelection--;
							else
								abilitySelection = 4;
						}
					}

				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
					if(!Command && !ItemMenu && !abilityMenu)
					{
						cursorMoved = true;
						cursorY++;
						if(cursorY >= tm->GetSizeY())
							cursorY = tm->GetSizeY() -1;
					}
						//tm->SetPosY(tm->GetPosY()- tm->GetTileSizeY());// * tm->GetScale()));
					else if(Command && !ItemMenu && !abilityMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice < 5)
							CmndChoice += 1;
						else
							CmndChoice = 0;
					}

					else if(abilityMenu && !Command && !ItemMenu)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(tm->ReturnHilightedTile(1)->GetCharacter()->GetType() != WIZARD)
						{
							if(abilitySelection < 3)
								abilitySelection++;
							else
								abilitySelection = 0;
						}
						else
						{
							if(abilitySelection < 4)
								abilitySelection++;
							else
								abilitySelection = 0;
						}
					}
					/*else if(ItemMenu && !Command)
					{
						if(ItemChoice < 3)
							ItemChoice += 1;
						else
							ItemChoice = 0;
					}*/
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
				{
					cursorMoved = true;
					cursorX--;
					if(cursorX < 0)
						cursorX = 0;
				}
					//tm->SetPosX(tm->GetPosX()+ tm->GetTileSizeX());// * tm->GetScale()));
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
				{
					cursorMoved = true;
					cursorX++;
					if(cursorX >= tm->GetSizeX())
						cursorX = tm->GetSizeX()-1;
				}
					//tm->SetPosX(tm->GetPosX()- tm->GetTileSizeX());// * tm->GetScale()));
				
				if(cursorMoved)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
					RECT cursorRect;
					cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
					cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
					cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
					cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

					if(cursorRect.left < 0)
					{
						tm->SetPosX(-cursorX*tm->GetTileSizeX());
					}
					if(cursorRect.right > Game::GetInstance()->GetWinWidth())
					{
						tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
					}
					if(cursorRect.top < 0)
					{
						tm->SetPosY(-cursorY*tm->GetTileSizeY());
					}
					if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
					{
						tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
					}
				}
				
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					if(!Movement && !Attack && !Command && !ItemMenu && !abilityMenu && !abilityTargeting)
					{
						activeTile = tm->ReturnHilightedTile(1);
						if(activeTile->GetCharacter() != nullptr && activeTile->GetCharacter()->IsPlayer())
							Command = true;
					}
					else if(Movement && !Attack && !Command && !ItemMenu && !abilityMenu && !abilityTargeting)
					{
						Tile * selected = tm->ReturnHilightedTile(1);
						Tile * start = Characters[0]->GetTile();
			
						if(selected->GetCharacter() == nullptr)
							if(activeTile->GetCharacter()->Move(selected))
							{
								if((selected->GetX() == 2 && selected->GetY() == 2))
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
									//convo = true;
									//currentMsg++;
									
									Movement = false;
									selected->GetCharacter()->SetMoved(false);
									
								}
			
								else
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);

									activeTile = start;
									selected->GetCharacter()->SetMoved(false);
									selected->GetCharacter()->Move(start);
									selected = activeTile;
									selected->GetCharacter()->SetMoved(false);									
								}
							}
							
							
							
							
					}

					else if(Command && !Attack && !Movement && !ItemMenu)
					{
						switch(CmndChoice)
						{
						case 0:
							{
								return true;
								break;
							}
					
						case 1:
							{
								return true;
								break;
							}
					
						case 2:
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							currentMsg++;
							convo = true;
							abilityMenu = true;
							break;
					
						case 3:
							return true;
							break;
					
						case 4:
							{
								return true;
								break;
							}
					
						case 5:
							break;
						};
						Command = false;
					}

					else if(abilityMenu && !ItemMenu && !Command && !Attack && !Movement && !abilityTargeting)
					{
						
						switch (this->activeTile->GetCharacter()->GetType())
						{
						case WIZARD:
							{
								switch(abilitySelection)
								{
								case 4:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
										abilityMenu = false;
										Command = true;
										break;
									}
								case 0 :
									HighlightAction(true,activeTile->GetCharacter()->GetRng());
									CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
									abilityMenu = false;
									abilityTargeting = true;
									break;

								//default:
								//	{
								//		abilityMenu = false;
								//		abilityTargeting = true;
								//		break;
								//	}
								};
								break;
					
							}
						case KNIGHT:
							{
								switch(abilitySelection)
								{
								case 3:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
										abilityMenu = false;
										Command = true;
										break;
									}
								case 0:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										this->activeTile->GetCharacter()->UseAbility(REINFORCED_CARDBOARD,activeTile);
										abilityMenu = false;
										break;
									}
								default:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										abilityMenu = false;
										abilityTargeting = true;
										break;
									}
								};
								break;
							}
						case ARCHER:
							{
								switch(abilitySelection)
								{
								case 3:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
										abilityMenu = false;
										Command = true;
										break;
									}
								default:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										abilityMenu = false;
										abilityTargeting = true;
										break;
									}
								};
								break;
							}
						case ROGUE:
							{
								switch(abilitySelection)
								{
								case 3:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
										abilityMenu = false;
										Command = true;
										break;
									}
								case 0:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										this->activeTile->GetCharacter()->UseAbility(HIDE,activeTile);
										abilityMenu = false;
										break;
									}
								default:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										abilityMenu = false;
										abilityTargeting = true;
										break;
									}
								};
								break;
							}
						case BLACK_KNIGHT:
							{
								switch(abilitySelection)
								{
								case 3:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
										abilityMenu = false;
										Command = true;
										break;
									}
								case 1:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										this->activeTile->GetCharacter()->UseAbility(BITE_KNEE_CAPS,activeTile);
										abilityMenu = false;
										break;
									}
								case 2:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										this->activeTile->GetCharacter()->UseAbility(GUARD_BRIDGE,activeTile);
										abilityMenu = false;
										break;
									}
								default:
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										abilityMenu = false;
										abilityTargeting = true;
										break;
									}
								};
								break;
							}
						}
					}
					else if(abilityTargeting && !abilityMenu && !ItemMenu && !Command && !Attack && !Movement)
					{
						Tile* selected = tm->ReturnHilightedTile(1);
						

						switch(activeTile->GetCharacter()->GetType())
						{
						case WIZARD:
							{
								switch(abilitySelection)
								{
								case 0:
									{
										GamePlayState::GetInstance()->SetPlayVoice(true);
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(LIGHTNING_BOLT,selected, 0);

										if(!abilityTargeting)
										{
											CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
											//currentMsg++;
											//convo = true;
										}

										else
										{
											CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
											HighlightAction(true,activeTile->GetCharacter()->GetRng());
											return true;
										}

										break;
									}
								case 1:
									{
										//abilityTargeting = !activeTile->GetCharacter()->UseAbility(FIRE_BALLS,selected, 1);
										return true;
										break;
									}
								case 2:
									{
										//abilityTargeting = !activeTile->GetCharacter()->UseAbility(TSUNAMI,selected, 1);
										return true;
										break;
									}
								case 3:
									{
										//abilityTargeting = !activeTile->GetCharacter()->UseAbility(PEROXIDE,selected, 1);
										return true;
										break;
									}
					
								};
								break;
							}
						case KNIGHT:
							{
								switch(abilitySelection)
								{
								case 1:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(SHIELD_BASH,selected);
										break;
									}
								case 2:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(COVER,selected);
										break;
									}
					
								};
								break;
							}
						case ROGUE:
							{
								switch(abilitySelection)
								{
								case 1:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(BACKSTAB,selected);
										break;
									}
								case 2:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(INFLICT_ALLERGIES,selected);
										break;
									}
								
					
								};
								break;
							}
						case ARCHER:
							{
								switch(abilitySelection)
								{
								case 0:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(MULTI_SHOT,selected);
										break;
									}
								case 1:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(SHOOT_HARDER,selected);
										break;
									}
								case 2:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(SHOOT_FARTHER,selected);
										break;
									}
					
								};
								break;
							}
						case BLACK_KNIGHT:
							{
								switch(abilitySelection)
								{
								case 0:
									{
										abilityTargeting = !activeTile->GetCharacter()->UseAbility(TAUNT,selected);
										break;
									}
					
								};
								break;
							}
					
						};
					
					}

				}

			}
		}

//***************************************************************End Ability Tutorial********************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************Begin Tile Tutorial*********************************************************************************************************//
		if(tutTiles)
		{
			gameGrid->SetScale(1.0f);
			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

					currentMsg++;

					if(currentMsg == 10 || currentMsg == 15)
					{
						cursorX = 0;
						cursorY += 2;
					}

					else if (currentMsg > 5 && currentMsg < 18 && currentMsg != 10 && currentMsg != 15)
						cursorX += 2;
				
						if(currentMsg == 20)
						{
							Reset();
						}
				}
			}
		}

//****************************************************************End Tile Tutorial**********************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//***********************************************************Begin Special Win Tutorial******************************************************************************************************//
			if(tutSpecialWin)
			{
				
				if(convo)
				{
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

						currentMsg++;

						if( currentMsg == 13)
							convo = false;

						if(currentMsg == 18)
						{
							Reset();
						}
					}
				}

				else
				{
				
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
					if(!Command && !ItemMenu)
					{
						cursorMoved = true;
						cursorY--;
						if(cursorY < 0)
							cursorY = 0;
					}
					else if(Command)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(CmndChoice > 0)
							CmndChoice -= 1;
						else
							CmndChoice = 5;
					}
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
						if(!Command && !ItemMenu)
						{
							cursorMoved = true;
							cursorY++;
							if(cursorY >= tm->GetSizeY())
								cursorY = tm->GetSizeY() -1;
						}
						
						else if(Command)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
							if(CmndChoice < 5)
								CmndChoice += 1;
							else
								CmndChoice = 0;
						}
						
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
					{
						cursorMoved = true;
						cursorX--;
						if(cursorX < 0)
							cursorX = 0;
					}

					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
					{
						cursorMoved = true;
						cursorX++;
						if(cursorX >= tm->GetSizeX())
							cursorX = tm->GetSizeX()-1;
					}


					if(cursorMoved)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						RECT cursorRect;
						cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
						cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
						cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
						cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

						if(cursorRect.left < 0)
						{
							tm->SetPosX(-cursorX*tm->GetTileSizeX());
						}
						if(cursorRect.right > Game::GetInstance()->GetWinWidth())
						{
							tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
						}
						if(cursorRect.top < 0)
						{
							tm->SetPosY(-cursorY*tm->GetTileSizeY());
						}
						if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
						{
							tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
						}
					}

					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
					{
						
						if(!Movement && !Attack && !Command && !ItemMenu)
						{
							activeTile = tm->ReturnHilightedTile(1);
							if(activeTile->GetCharacter() != nullptr && activeTile->GetCharacter()->IsPlayer())
							{
								CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
								Command = true;

							}
						}
						else if(Movement)
						{
							HighlightMove();
							Tile * selected = tm->ReturnHilightedTile(1);
							Tile * start = Characters[0]->GetTile();
							if(selected->GetCharacter() == nullptr)
								if(activeTile->GetCharacter()->Move(selected, 1))
								{
									if((selected->GetX() == 2 && selected->GetY() == 6))
									{
										//convo = true;
										//currentMsg++;
										CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
										Movement = false;
										selected->GetCharacter()->SetMoved(false);
									}


									else
									{
										CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
										activeTile = start;
										selected->GetCharacter()->SetMoved(false);
										selected->GetCharacter()->Move(start, 1);
										selected = activeTile;
										selected->GetCharacter()->SetMoved(false);
										this->HighlightMove();
										
									}
								}		
						}

						else if(Command && !Attack && !Movement && !ItemMenu)
						{
							
							
							switch(CmndChoice)
							{
							case 0:
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
									Movement = true;
									this->HighlightMove();
									break;
								}

							case 1:
								{
									return true;
									break;
								}

							case 2:
								return true;
								break;

							case 3:
								return true;
								break;

							case 4:
								return true;
									break;
								

							case 5:
								break;
							};

							Command = false;
						}

					}
				}
			}
//**************************************************************End Special Win Tutorial*****************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************Begin Weather Tutorial******************************************************************************************************//
		if(tutWeather)
		{
			gameGrid->SetScale(2.0f);
			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

					currentMsg++;

					if(currentMsg == 6 || currentMsg == 10)
					{
						WS->ChangeWeather("Sun.xml");
					}

					else if(currentMsg == 8)
					{					
						WS->ChangeWeather("Rain.xml");
					}

					else if(currentMsg == 9)
					{
						WS->ChangeWeather("Snow.xml");
					}
						if(currentMsg == 12)
						{
							Reset();
						}
				}
			}
		}

//****************************************************************End Weather Tutorial*******************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************Begin Spawnpoint Tutorial****************************************************************************************************//
		if(tutSpawnPoint)
		{
			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

					currentMsg++;
					
					/*
						activeTile = tm->ReturnHighlightedTile(1);
						std::string tempString = "playerSpawnPoint";

						if(activeTile->GetEventString() == tempString)
						{
							if(activeTile->GetCharacter() == nullptr)
							{
								Chracters[0]->SetTile(activeTile);
								activeTile->SetCharacter(Characters[0]);
							}
						}
					*/
					if(currentMsg == 12 || currentMsg == 18)
					{
						convo = false;
					}
				
					if(currentMsg == 22)
					{
						Reset();
					}
				}
			}

			else
			{

				if(prebattle)
				{
					CSGD_DirectInput * di = CSGD_DirectInput::GetInstance();
				
					if(di->KeyPressed(DIK_UP)||arcadeUp)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(this->leftSideSelecting)
						{
							this->preLeftSelection--;
							if(preLeftSelection < 0)
								preLeftSelection = selectFrom.size()-1;
						}
						else
						{
							this->preRightSelection--;
							if(preRightSelection < 0)
								preRightSelection = selected.size()-1;
						}
					}
				
					if(di->KeyPressed(DIK_DOWN)||arcadeDown)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

						if(this->leftSideSelecting)
						{
							this->preLeftSelection++;
							if(preLeftSelection >= (int)selectFrom.size())
								preLeftSelection = 0;
						}
						else
						{
							this->preRightSelection++;
							if(preRightSelection >= (int)selected.size())
								preRightSelection = 0;
						}
					}
				
					if(di->KeyPressed(DIK_LEFT)||arcadeLeft)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						preLeftSelection = 0;
						this->leftSideSelecting = true;
					}
				
					if(di->KeyPressed(DIK_RIGHT)||arcadeRight)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						preRightSelection = 0;
						if(selected.size() > 0)
							this->leftSideSelecting = false;
					}
				
					if(di->KeyPressed(DIK_RETURN)||arcadeEnter)
					{
						if(this->leftSideSelecting)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							selected.push_back(selectFrom[preLeftSelection]);
							selectFrom.erase(selectFrom.begin()+preLeftSelection);
							preLeftSelection = 0;
						}
						else
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
							selectFrom.push_back(selected[preRightSelection]);
							selected.erase(selected.begin()+preRightSelection);
							preRightSelection = 0;
							if(selected.size() <= 0)
								leftSideSelecting = true;
						}
				
						if(selected.size() == 4)
						{
							for(unsigned int i = 0; i < selected.size();i++)
							{
								//TakeCharacterMsg* pMSG = new TakeCharacterMsg(selected[i]);
								//MS->SendMsg(pMSG);
								this->CharactersToTake.push_back(selected[i]);
								SizeOfParty++;
							}
				
							SelectingaTile = true;
							prebattle = false;
							convo = true;
							currentMsg++;
						}
				
					}
				
				}


				else if(SelectingaTile && !StatsMenu && !abilityTargeting && !abilityMenu && !ItemMenu && !Command && !Attack && !Movement)
				{

					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
						if(!Command && !ItemMenu && !abilityMenu)
						{
							cursorMoved = true;
							cursorY--;
							if(cursorY < 0)
								cursorY = 0;
						}
					
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
						if(!Command && !ItemMenu && !abilityMenu)
						{
							cursorMoved = true;
							cursorY++;
							if(cursorY >= tm->GetSizeY())
								cursorY = tm->GetSizeY() -1;
						}

					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
					{
						cursorMoved = true;
						cursorX--;
						if(cursorX < 0)
							cursorX = 0;
					}
						//tm->SetPosX(tm->GetPosX()+ tm->GetTileSizeX());// * tm->GetScale()));
					if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
					{
						cursorMoved = true;
						cursorX++;
						if(cursorX >= tm->GetSizeX())
							cursorX = tm->GetSizeX()-1;
					}
						//tm->SetPosX(tm->GetPosX()- tm->GetTileSizeX());// * tm->GetScale()));
					
					if(cursorMoved)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
						RECT cursorRect;
						cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
						cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
						cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
						cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

						if(cursorRect.left < 0)
						{
							tm->SetPosX(-cursorX*tm->GetTileSizeX());
						}
						if(cursorRect.right > Game::GetInstance()->GetWinWidth())
						{
							tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
						}
						if(cursorRect.top < 0)
						{
							tm->SetPosY(-cursorY*tm->GetTileSizeY());
						}
						if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
						{
							tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
						}
					}

					CSGD_DirectInput * di = CSGD_DirectInput::GetInstance();
					if(di->KeyPressed(DIK_RETURN)||arcadeEnter)
					{
						activeTile = tm->ReturnHilightedTile(1);
						std::string temp = "playerSpawnPoint";
				
						if(activeTile->GetEventString() == temp)
						{
							if(activeTile->GetCharacter() == nullptr)
							{
								if(SelectingCount != CharactersToTake.size())
								{
									CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

									CharactersToTake[SelectingCount]->SetTile(activeTile);
									activeTile->SetCharacter(CharactersToTake[SelectingCount]);
									SelectingCount++;
								}
							}

							else
								CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
						
						}

						else
							CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					}
						if((unsigned int)SelectingCount >= CharactersToTake.size())
						{
							SelectingaTile = false;
							convo = true;
							currentMsg++;
						}
				}
			}
		}

//****************************************************************End Spawnpoint Tutorial****************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//****************************************************************Begin Class Tutorial*******************************************************************************************************//
		if(tutCharExplain)
		{
			gameGrid->SetScale(2.0f);
			if(convo)
			{
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					currentMsg++;
					cursorY = 3;
					if(currentMsg == 3)
					{
						cursorX = 1;
					}

					else if(currentMsg == 10)
					{
						cursorX = 2;
					}

					else if(currentMsg == 17)
					{
						cursorX = 3;
					}

					else if(currentMsg == 27)
					{
						cursorX = 4;
					}

					else if(currentMsg == 35)
					{
						cursorX = 5;
					}
				
					if(currentMsg == 43)
					{
						Reset();
					}
				}
			}
		}

//*****************************************************************End Class Tutorial********************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

			//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP))
			//	if(!Command && !ItemMenu)
			//	{
			//		cursorMoved = true;
			//		cursorY--;
			//		if(cursorY < 0)
			//			cursorY = 0;
			//	}
			//	else if(Command && !ItemMenu)
			//	{
			//		if(CmndChoice > 0)
			//			CmndChoice -= 1;
			//		else
			//			CmndChoice = 5;
			//	}
			//	else if(ItemMenu && !Command)
			//	{
			//		if(ItemChoice > 0)
			//			ItemChoice -= 1;
			//		else
			//			ItemChoice = 3;
			//	}
			//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN))
			//	if(!Command && !ItemMenu)
			//	{
			//		cursorMoved = true;
			//		cursorY++;
			//		if(cursorY >= tm->GetSizeY())
			//			cursorY = tm->GetSizeY() -1;
			//	}
			//		//tm->SetPosY(tm->GetPosY()- tm->GetTileSizeY());// * tm->GetScale()));
			//	else if(Command && !ItemMenu)
			//	{
			//		if(CmndChoice < 5)
			//			CmndChoice += 1;
			//		else
			//			CmndChoice = 0;
			//	}
			//	else if(ItemMenu && !Command)
			//	{
			//		if(ItemChoice < 3)
			//			ItemChoice += 1;
			//		else
			//			ItemChoice = 0;
			//	}
			//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT))
			//{
			//	cursorMoved = true;
			//	cursorX--;
			//	if(cursorX < 0)
			//		cursorX = 0;
			//}
			//	//tm->SetPosX(tm->GetPosX()+ tm->GetTileSizeX());// * tm->GetScale()));
			//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT))
			//{
			//	cursorMoved = true;
			//	cursorX++;
			//	if(cursorX >= tm->GetSizeX())
			//		cursorX = tm->GetSizeX()-1;
			//}
			//	//tm->SetPosX(tm->GetPosX()- tm->GetTileSizeX());// * tm->GetScale()));

			//if(cursorMoved)
			//{
			//	RECT cursorRect;
			//	cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
			//	cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
			//	cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
			//	cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

			//	if(cursorRect.left < 0)
			//	{
			//		tm->SetPosX(-cursorX*tm->GetTileSizeX());
			//	}
			//	if(cursorRect.right > Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.25f))
			//	{
			//		tm->SetPosX((int)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.25f))/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
			//	}
			//	if(cursorRect.top < 0)
			//	{
			//		tm->SetPosY(-cursorY*tm->GetTileSizeY());
			//	}
			//	if(cursorRect.bottom > Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.25f))
			//	{
			//		tm->SetPosY((int)((Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.25f))/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
			//	}
			//}

			//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN))
			//{
			//	if(!Movement && !Attack && !Command && !ItemMenu)
			//	{
			//		activeTile = tm->ReturnHilightedTile();
			//		if(activeTile->GetCharacter() != nullptr && activeTile->GetCharacter()->IsPlayer())
			//			Command = true;
			//	}
			//	else if(Movement && !Attack && !Command && !ItemMenu)
			//	{
			//		Tile * selected = tm->ReturnHilightedTile();
			//		if(selected->GetCharacter() == nullptr)
			//			if(activeTile->GetCharacter()->Move(selected))
			//			{
			//				Movement = false;
			//				selected->GetCharacter()->SetMoved(false);
			//			}
			//	}
			//	else if(Attack && !Movement && !Command && !ItemMenu)
			//	{
			//		Tile * selected = tm->ReturnHilightedTile();
			//		if(selected->GetCharacter() != nullptr && selected->GetCharacter()->IsPlayer() == false)
			//			if(activeTile->GetCharacter()->Attack(selected))
			//			{
			//				Attack = false;
			//				activeTile->GetCharacter()->SetActed(false);
			//			}
			//	}
			//	else if(Command && !Attack && !Movement && !ItemMenu)
			//	{
			//		switch(CmndChoice)
			//		{
			//		case 0:
			//			{
			//				Movement = true;
			//				break;
			//			}

			//		case 1:
			//			{
			//				Attack = true;
			//				break;
			//			}

			//		case 2:
			//			break;

			//		case 3:
			//			break;

			//		case 4:
			//			{
			//				ItemMenu = true;
			//				break;
			//			}

			//		case 5:
			//			break;
			//		};
			//		Command = false;
			//	}
			//	else if(ItemMenu && !Command && !Attack && !Movement)
			//	{
			//		switch(ItemChoice)
			//		{
			//		case 0:
			//			{
			//				if(HPotions != 0)
			//				{
			//					vector<Item*>::iterator iter = Inventory.begin();
			//					for( ; iter != Inventory.end(); ++iter)
			//					{
			//						if((*iter)->GetID() == HPOTION)
			//						{
			//							if(activeTile->GetCharacter()->UseItem(*iter))
			//							{
			//								HPotions -= 1;
			//								delete(*iter);
			//								Inventory.erase(iter);
			//								ItemMenu = false;
			//								break;
			//							}
			//							else
			//								break;
			//						}
			//					}
			//				}
			//				else
			//					break;
			//			}

			//		case 1:
			//			{
			//				if(MPotions != 0)
			//				{
			//					vector<Item*>::iterator iter = Inventory.begin();
			//					for( ; iter != Inventory.end(); ++iter)
			//					{
			//						if((*iter)->GetID() == MPOTION)
			//						{
			//							if(activeTile->GetCharacter()->UseItem(*iter))
			//							{
			//								MPotions -= 1;
			//								delete(*iter);
			//								Inventory.erase(iter);
			//								ItemMenu = false;
			//								break;
			//							}
			//							else
			//								break;
			//						}
			//					}
			//				}
			//				else
			//					break;
			//			}

			//		case 2:
			//			{
			//				if(Inhalers != 0)
			//				{
			//					vector<Item*>::iterator iter = Inventory.begin();
			//					for( ; iter != Inventory.end(); ++iter)
			//					{
			//						if((*iter)->GetID() == INHALER)
			//						{
			//							if(activeTile->GetCharacter()->UseItem(*iter))
			//							{
			//								Inhalers -= 1;
			//								delete(*iter);
			//								Inventory.erase(iter);
			//								ItemMenu = false;
			//								break;
			//							}
			//							else
			//								break;
			//						}
			//					}
			//				}
			//				else
			//					break;
			//			}

			//		case 3:
			//			{
			//				Command = true;
			//				ItemMenu = false;
			//			}
			//		};
			//	}
			//}


			////////////////////////////////
			//test for movement
			//if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN))
			//	this->Characters[0]->Move(tm->GetTile(1,0));

			//static int i = 0;


			//if(CSGD_DirectInput::GetInstance()->MouseButtonPressed(0))
			//{
			//	
			//	this->Characters[0]->Move(tm->GetTile(0,i));
			//	i++;
			//	//this->Characters[0]->Move(tm->GetTile(CSGD_DirectInput::GetInstance()->MouseGetPosX()%(int)(tm->GetScale()*tm->GetTileSizeX()),CSGD_DirectInput::GetInstance()->MouseGetPosY()%(int)(tm->GetScale()*tm->GetTileSizeY())));			
			//}

			////////////////////////////////
		}
		
		else if(Paused)
		{
			if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
				Resume = !Resume;
			}

			if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
				Resume = !Resume;
			}

			if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);

				if(Resume)
					Paused = false;

				else if(!Resume)
				{
					Paused = false;
					Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
				}
			}
		}
	
	}
	return true;
}

bool TutorialPlayState::LoadFile(void)
{
	// Create the TinyXML Document
	TiXmlDocument doc;

	if(tutMove)
	doc.LoadFile("Move_and_Control_Instructions.xml");

	if(tutItem)
		doc.LoadFile("Item_Use_Instructions.xml");

	if(tutAttack)
		doc.LoadFile("Attack_Instructions.xml");

	if(tutAbility)
		doc.LoadFile("Ability_Usage_Instructions.xml");

	if(tutTiles)
		doc.LoadFile("Special_Tile_Instructions.xml");

	if(tutSpecialWin)
		doc.LoadFile("Special_Win_Instructions.xml");

	if(tutWeather)
		doc.LoadFile("Weather_Instructions.xml");

	if(tutSpawnPoint)
		doc.LoadFile("Spawn_and_Character_Selection_Instructions.xml");

	if(tutCharExplain)
		doc.LoadFile("Character_Class_Instructions.xml");

	TiXmlElement* pRoot = doc.RootElement();
	if(pRoot == nullptr)
		return false;

	tutConvo.clear();

	//TiXmlElement* pTutors = pRoot->FirstChildElement("Instructions");
	//
	//if(pTutors == nullptr)
	//{
	//	return false;
	//}

	TiXmlElement* pInstruct = pRoot->FirstChildElement("Instruction");

	if(pInstruct == nullptr)
	{
		return false;
	}

	while(pInstruct != nullptr)
	{
		if(pInstruct->Attribute("Statement") != nullptr)
		{
			tutConvo.push_back(pInstruct->Attribute("Statement"));
		}

		pInstruct = pInstruct->NextSiblingElement("Instruction");
	}
	tutorConvo = new char*[tutConvo.size()];
	for(unsigned int i=0; i < tutConvo.size(); ++i)
	{
		tutorConvo[i] = new char[tutConvo[i].length()];
		for(unsigned int j=0; j< tutConvo[i].length(); ++j)
		{
			
			tutorConvo[i][j] = tutConvo[i][j];
		}
	}
	return true;
}


void TutorialPlayState::Update(float fElapsedTime)
{
	// If the game isn't paused, update
	if(!Paused && !prebattle)
	{
		

		gameGrid->Update(fElapsedTime);
		if(!tutSpawnPoint)
		{
			vector<BaseCharacter*>::iterator iter = Characters.begin();
			for( ; iter != Characters.end(); ++iter)
			{
				(*iter)->Update(fElapsedTime);
			}
		}

		else
		{

			if(SelectingaTile == true)
			{
				if(SizeOfParty != 0)
				{
					vector<BaseCharacter*>::iterator iter;
					iter = CharactersToTake.begin();
			
					for( ; iter != CharactersToTake.end(); iter++)
					{
						Characters.push_back((*iter));
						SizeOfParty--;	
					}
				}
			}
			else
			{
				vector<BaseCharacter*>::iterator iter = Characters.begin();
			
				gameGrid->Update(fElapsedTime);
			
				for( ; iter != Characters.end(); ++iter)
				{
					(*iter)->Update(fElapsedTime);
				}
			
			}

		}

		if(fElapsedTime == 0)
			fElapsedTime = 0.0150f;

		vector<string>::iterator WeatherIter = keys.begin();

		for( ; WeatherIter != keys.end(); WeatherIter++)
		{
			if(WeatherIter->find(WS->GetKey()))
				ParticleManager::GetInstance()->Update(fElapsedTime);
		}

		MS->ProcessMessages();

		if(GamePlayState::GetInstance()->GetDiceRolled() == true)
		{
			GamePlayState::GetInstance()->SetDiceTime1(GamePlayState::GetInstance()->GetDiceTime1() + fElapsedTime);
			GamePlayState::GetInstance()->SetDShownTime(GamePlayState::GetInstance()->GetDShownTime() + fElapsedTime);
			Shotspeed2 += fElapsedTime * 7.0f;
		
			if(GamePlayState::GetInstance()->GetDiceTime1() > 15.0f)
			{
				GamePlayState::GetInstance()->SetDiceRolled(false);
				GamePlayState::GetInstance()->SetDiceTime1(0.0f);
				GamePlayState::GetInstance()->SetDiceShown(true);
				GamePlayState::GetInstance()->SetDShownTime(0.0f);
				Shotspeed2 = 0.0f;
			}
		}
		
		if(GamePlayState::GetInstance()->GetDiceShown() == true)
		{
			GamePlayState::GetInstance()->SetDiceTime2(GamePlayState::GetInstance()->GetDiceTime2() + fElapsedTime);
			Shotspeed += fElapsedTime * 7.0f;
			GamePlayState::GetInstance()->SetShotSpeed(Shotspeed);
		
			if(tutAbility)
				checktimer = 50.0f;

			if(tutAttack)
				checktimer = 25.0f;

			if(GamePlayState::GetInstance()->GetDiceTime2() > checktimer)
			{
					currentMsg++;
					convo = true;

				GamePlayState::GetInstance()->SetAtkTypeStorage(-1);
				GamePlayState::GetInstance()->SetAtkTypeStorage(AtkTypeStorage);
				Shotspeed = 0;
				Modifier = 0.0f;
				GamePlayState::GetInstance()->SetDiceTime2(0.0f);
				GamePlayState::GetInstance()->SetDiceShown(false);
				GamePlayState::GetInstance()->ClearDiceVectors();
				vector<string>::iterator iter = ActiveKeys.begin();
				GamePlayState::GetInstance()->SetSpellHit(false);
				GamePlayState::GetInstance()->SetThrownSound(true);
			}
		}
	}
	if(gameWon)
	{
		if(tutSpecialWin && currentMsg == 13)
		{
			convo = true;
			currentMsg++;
		}
		
		gameWonTimer += fElapsedTime;

		if(gameWonTimer >= 150)
		{	
			//Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
			tempAtk = Characters[0]->GetAtk();
			tempStm = Characters[0]->GetSta();
			tempDef = Characters[0]->GetDef();
			tempAgi = Characters[0]->GetAgi();
			tempSpd = Characters[0]->GetSpd();
			tempHP	= Characters[0]->GetHP();
			tempMP	= Characters[0]->GetMP();
			tempLvl = Characters[0]->GetLevel();
		}

	}
}

void TutorialPlayState::RenderDice()
{
	BattleWindowFade();
	
	RECT BRECT = {Game::GetInstance()->GetWinWidth()/2 - 350, Game::GetInstance()->GetWinHeight()/2 - 250, Game::GetInstance()->GetWinWidth()/2 + 350, Game::GetInstance()->GetWinHeight()/2 + 250 };
	
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.top, BRECT.right, BRECT.top, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.top, BRECT.left, BRECT.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.right, BRECT.top, BRECT.right, BRECT.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.bottom, BRECT.right, BRECT.bottom, 255, 0, 0);
	
	BattleWindow();

	int size = DiceImages.size();
	int random = 0;
	int randX = 0;
	int randY = 0;
	int i = 0;
	RECT rect = diceRECT;


	random = rand() % size;
	randX = rand() % (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[random]) / 64);
	randY = rand() % (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[random]) / 51);

	if(DShownTime >= 0.0f && DShownTime <= 0.2f || DShownTime >= 3.0f && DShownTime <= 3.2f || DShownTime >= 5.0f && DShownTime <= 5.2f || DShownTime >= 7.0f && DShownTime <= 7.2f || DShownTime >= 9.0f && DShownTime <= 9.2f)
	{
		diceRECT = DiceCell(randX, randY);

		if(rect.left == diceRECT.left && rect.right == diceRECT.right && rect.top == diceRECT.top && rect.bottom == diceRECT.bottom)
				diceRECT = DiceCell(randX, randY);
	}

	CSGD_TextureManager::GetInstance()->Draw(DiceImages[random], 200, 200, 1.0f, 1.0f, &diceRECT,
				0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

	CSGD_TextureManager::GetInstance()->Draw(DiceImages[random], 400, 200, 1.0f, 1.0f, &diceRECT,
				0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
	
}

void TutorialPlayState::RenderRoll()
{
	int atkX = 0;
	int atkY = 0;
	int atkImage =  -1;
	RECT atkrect = {0, 0, 0, 0};

	int DefX = 0;
	int DefY = 0;
	int DefImage = -1;
	RECT Defrect = {0, 0, 0, 0};

	int Asize = AtkRolls.size();
	int Dsize = DefRolls.size();

	for(int i = 0; i < Asize; i++)
	{
		if(AtkRolls[i] == 4)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 6)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 8)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 125);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 63);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 10)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 12)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 20)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			atkImage = 1;
		}

		//attack roll
		if(ARolls[i] < atkX)
		{
			atkX = 0;
		}
		else
		{
			if(ARolls[i] % atkX == 0)
			{
				atkX = 1;
			}
			else
				atkX = 0;
		}

		if(ARolls[i] % 2 == 0)
		{
			atkY = (ARolls[i] / 2) - 1;
		}
		else
			atkY = ARolls[i] / 2;


		atkrect = DiceCell(atkX, atkY);

		CSGD_TextureManager::GetInstance()->Draw(DiceImages[atkImage], 100 + (i*64), 200, 1.0f, 1.0f, &atkrect,
		0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
	}

	for(int i = 0; i < Dsize; i++)
	{
		if(DefRolls[i] == 4)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 6)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 8)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 125);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 63);
			DefImage = 0;
		}
		else if(DefRolls[i] == 10)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 12)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[0]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[0]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 20)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			DefImage = 1;
		}

		//Defense roll
		if(DRolls[i] < DefX)
		{
			DefX = 0;
		}
		else
		{
			if(DRolls[i] % DefX == 0)
			{
				DefX = 1;
			}
			else
				DefX = 0;
		}

		if(DRolls[i] % 2 == 0)
		{
			DefY = (DRolls[i] / 2) - 1;
		}
		else
			DefY = DRolls[i] / 2;

		Defrect = DiceCell(DefX, DefY);

		CSGD_TextureManager::GetInstance()->Draw(DiceImages[DefImage], 400 + (i*64), 200, 1.0f, 1.0f, &Defrect,
			0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
	}


	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
}

RECT TutorialPlayState::DiceCell(int X, int Y)
{
	RECT DiceRECT = {0, 0, 0, 0};

	DiceRECT.left = X*64;
	DiceRECT.top = Y*51;
	DiceRECT.right = DiceRECT.left + 64;
	DiceRECT.bottom = DiceRECT.top + 51;
	
	return DiceRECT;
}

void TutorialPlayState::Render(void)
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};

	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	/*RECT r;
	r.top = 200;
	r.left = 200;
	r.bottom = 400;
	r.right = 400;*/

	// To ensure text is on top
	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();

	if(tutMenu)
	{
		pTM->Draw(BackgroundID,0,-138,0.8f,0.72f);

		pTM->Draw(PanelID, 160, 5, 2.2f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 160, 45, 2.2f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		
		pTM->Draw(PanelID, 90, 85, 3.0f, 2.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(195,255,255,255));
		pTM->Draw(PanelID, 90, 163, 3.0f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(195,255,255,255));
		pTM->Draw(PanelID, 90, 257, 3.0f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(195,255,255,255));
		pTM->Draw(PanelID, 90, 360, 3.0f, 2.9f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(195,255,255,255));
		pTM->Draw(PanelID, 90, 496, 3.0f, 3.1f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(195,255,255,255));
		
		Font.Print("What Tutorial do you wish to view?", 175, 25, 1.0f);
		Font.Print("How to: Controls and Movement", 135, 95, 1.0f);
		Font.Print("How to: Attacking", 135, 145, 1.0f);
		Font.Print("How to: Using Items", 135, 195, 1.0f);
		Font.Print("How to: Using Abilities", 135, 245, 1.0f);
		Font.Print("Special Tiles", 135, 295, 1.0f);
		Font.Print("Special Win Conditions", 135, 345, 1.0f);
		Font.Print("Weather Conditions", 135, 395, 1.0f);
		Font.Print("How To: Party Formation and Spawn Points", 135, 445, 1.0f);
		Font.Print("Class and Character Explanations", 135, 495, 1.0f);
		Font.Print("Exit Tutorial", 135, 545, 1.0f);

		pTM->Draw(CursorID, 110, 105 + (50 * MenuChoice));
	}
	//CSGD_Direct3D::GetInstance()->DrawRect(r,0,0,0);

	/*vector<BaseCharacter*>::iterator iter = Characters.begin();

	for( ; iter != Characters.end(); ++iter)
		{
			(*iter)->Render();
		}*/

	//else if(gameWon2)
	//{
	//	Font.Print("You have gained", 30, 30, 1.0f);
	//	char buffer[50];
	//	sprintf_s(buffer, "%d", Characters[0]->GetExp());
	//	Font.Print(buffer, 230, 30, 1.0f);
	//	Font.Print("experience this battle!", 255, 30, 1.0f);

	//	Characters[1]->SetHP(50);

	//	// Increase the character's stats
	//	if(Characters[0]->GetExp() > 100)
	//	Characters[0]->LevelUp();

	//	if(tempLvl < Characters[0]->GetLevel())
	//	{
	//		Font.Print("You have leveled up!", 200, 100, 2.0f);
	//		Font.Print("Your stats have been upgraded!", 200, 150, 2.0f);

	//		// Displaying before-increase stats
	//		Font.Print("HP:", 20, 200, 1.0f);
	//		sprintf_s(buffer, "%d", tempHP);
	//		Font.Print(buffer, 120, 200, 1.0f);

	//		Font.Print("MP:", 20, 230, 1.0f);
	//		sprintf_s(buffer, "%d", tempMP);
	//		Font.Print(buffer, 120, 230, 1.0f);

	//		Font.Print("Attack:", 20, 260, 1.0f);
	//		sprintf_s(buffer, "%d", tempAtk);
	//		Font.Print(buffer, 120, 260, 1.0f);

	//		Font.Print("Defense:", 20, 290, 1.0f);
	//		sprintf_s(buffer, "%d", tempDef);
	//		Font.Print(buffer, 120, 290, 1.0f);

	//		Font.Print("Speed:", 20, 320, 1.0f);
	//		sprintf_s(buffer, "%d", tempSpd);
	//		Font.Print(buffer, 120, 320, 1.0f);

	//		Font.Print("Agility:", 20, 350, 1.0f);
	//		sprintf_s(buffer, "%d", tempAgi);
	//		Font.Print(buffer, 120, 350, 1.0f);

	//		Font.Print("Stamina:", 20, 380, 1.0f);
	//		sprintf_s(buffer, "%d", tempStm);
	//		Font.Print(buffer, 120, 380, 1.0f);


	//		// Displaying post-increase stats

	//		Font.Print("New HP:", 200, 200, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetHP());
	//		Font.Print(buffer, 360, 200, 1.0f);
	//		
	//		Font.Print("New MP:", 200, 230, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetMP());
	//		Font.Print(buffer, 360, 230, 1.0f);
	//		
	//		Font.Print("New Attack:", 200, 260, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetAtk());
	//		Font.Print(buffer, 360, 260, 1.0f);
	//		
	//		Font.Print("New Defense:", 200, 290, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetDef());
	//		Font.Print(buffer, 360, 290, 1.0f);
	//		
	//		Font.Print("New Speed:", 200, 320, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetSpd());
	//		Font.Print(buffer, 360, 320, 1.0f);
	//		
	//		Font.Print("New Agility:", 200, 350, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetAgi());
	//		Font.Print(buffer, 360, 350, 1.0f);
	//		
	//		Font.Print("New Stamina:", 200, 380, 1.0f);
	//		sprintf_s(buffer, "%d", Characters[0]->GetSta());
	//		Font.Print(buffer, 360, 380, 1.0f);

	//	}
			
	//}
	// Draw 
	if(gameWon)
	{
		pTM->Draw(BackgroundID,0,-138,0.8f,0.72f);
		Font.Print("YOU WIN!!!", 200, 30, 3.0f);

		if(tutSpecialWin)
		{
			//RECT textbox = {10,(LONG)(Game::GetInstance()->GetWinHeight() * 0.85f), (LONG)(Game::GetInstance()->GetWinWidth() * .80f), (LONG)(Game::GetInstance()->GetWinHeight() * 0.95f)};
			//CSGD_Direct3D::GetInstance()->DrawRect(textbox, 0, 0, 200);
			pTM->Draw(PanelID, -2, 505, 3.12f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, -2, 540, 3.12f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			
			Font.Print(tutConvo[currentMsg].c_str(), 20 /*+ (Font.GetCharWidthW() * i)*/, (int)(Game::GetInstance()->GetWinHeight() * 0.85f), 1.0f);
		}
	
	}

	else if(prebattle)
	{
		pTM->Draw(BackgroundID,0,-138,0.8f,0.72f);
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7f)) - 10, 73, 1.7f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7f)) - 10, 113, 1.7f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		Font.Print("Select Fighters",(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7f)),83,2.0f);
		//Font.Print("Take into Battle",(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),100,2.0f);

		// Left Panel
		pTM->Draw(PanelID, 50, 150, 1.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 50, 200, 1.4f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 50, 300, 1.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 50, 365, 1.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		// Right Panel
		pTM->Draw(PanelID, 370, 150, 1.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 370, 200, 1.4f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 370, 300, 1.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 370, 365, 1.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		if(this->leftSideSelecting)
			pTM->Draw(this->CursorID,(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.93f)),165+(this->preLeftSelection*30));
		else
			pTM->Draw(this->CursorID,(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.53f)),165+(this->preRightSelection*30));

		for(unsigned int i = 0; i < selectFrom.size();i++)
		{
			string s;

			switch(selectFrom[i]->GetType())
			{
			case KNIGHT:
				{
					s = "Cardboard Knight";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),160+(i*30),1.0f);
					break;														  
				}																  
			case ARCHER:														  
				{																  
					s = "Generic Archer";										  
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),160+(i*30),1.0f);
					break;														  
				}																  
			case WIZARD:														  
				{																  
					s = "Internet Wizard";										  
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),160+(i*30),1.0f);
					break;
				}
			case ROGUE:
				{
					s = "Obvious Rogue";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),160+(i*30),1.0f);
					break;
				}
			case BLACK_KNIGHT:
				{
					s = "Blackish Knight";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),160+(i*30),1.0f);
					break;
				}
			};
		}

		for(unsigned int i = 0; i < selected.size();i++)
		{
			string s;

			switch(selected[i]->GetType())
			{
			case KNIGHT:
				{
					s = "Cardboard Knight";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),160+(i*30),1.0f);
					break;
				}
			case ARCHER:
				{
					s = "Generic Archer";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),160+(i*30),1.0f);
					break;
				}
			case WIZARD:
				{
					s = "Internet Wizard";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),160+(i*30),1.0f);
					break;
				}
			case ROGUE:
				{
					s = "Obvious Rogue";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),160+(i*30),1.0f);
					break;
				}
			case BLACK_KNIGHT:
				{
					s = "Blackish Knight";
					Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),160+(i*30),1.0f);
					break;
				}
			};
		}

		BaseCharacter * bc;
		if(this->leftSideSelecting)
			 bc = selectFrom[preLeftSelection];
		else
			 bc = selected[preRightSelection];

		pTM->Draw(PanelID, 65, 420, 2.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 65, 470, 2.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 65, 540, 2.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		string sBuffer = "Stats:";
		char cBuffer[8];
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+10,1.0f);
																																								  
		sprintf_s(cBuffer, "%d", bc->GetLevel());																												  
		sBuffer = "Level: ";																																	  
		sBuffer += cBuffer;																																		  
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+40,1.0f);
																																								  
		sprintf_s(cBuffer, "%d", bc->GetExp());																													  
		sBuffer = "Exp: ";																																		  
		sBuffer += cBuffer;																																		  
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+70,1.0f);
																																								  
		sprintf_s(cBuffer, "%d", bc->GetMaxHP());																												  
		sBuffer = "Max HP: ";																																	  
		sBuffer += cBuffer;																																		  
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+100,1.0f);
																																								  
		sprintf_s(cBuffer, "%d", bc->GetMov());																													  
		sBuffer = "Movement: ";																																	  
		sBuffer += cBuffer;																																		  
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+130,1.0f);

		sprintf_s(cBuffer, "%d", bc->GetAtk());		
		sBuffer = "Attack: ";
		sBuffer += cBuffer;
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.5f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+40,1.0f);

		sprintf_s(cBuffer, "%d", bc->GetDef());		
		sBuffer = "Defense: ";
		sBuffer += cBuffer;
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.5f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+70,1.0f);

		sprintf_s(cBuffer, "%d", bc->GetRng());		
		sBuffer = "Range: ";
		sBuffer += cBuffer;
		Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.5f)),(int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.3f))+100,1.0f);

		//RECT textbox = {10,(LONG)(Game::GetInstance()->GetWinHeight() * 0.01f), (LONG)(Game::GetInstance()->GetWinWidth() * .80f), (LONG)(Game::GetInstance()->GetWinHeight() * 0.08f)};
		//CSGD_Direct3D::GetInstance()->DrawRect(textbox, 0, 0, 200);

		pTM->Draw(PanelID, -2, 5, 3.2f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, -2, 40, 3.2f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		Font.Print(tutConvo[currentMsg].c_str(), 22 /*+ (Font.GetCharWidthW() * i)*/, (int)(Game::GetInstance()->GetWinHeight() * 0.03f), 1.0f);

	}	

	else if(prebattle == false && tutMenu == false)
	{
		
		if(StatsMenu)
		{

			char buff[50];
		
			switch(Viewing->GetType())
				{
				case KNIGHT:
					{
						Font.Print("Knight", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case ARCHER:
					{
						Font.Print("Archer", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case ROGUE:
					{
						Font.Print("Rogue", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case WIZARD:
					{
						Font.Print("Wizard", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case BLACK_KNIGHT:
					{
						Font.Print("Black Knight", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				};
				Font.Print("Level: ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.4)), 60, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetLevel());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.2)), 60, 2.0f);
				Font.Print("Exp: ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.4)), 110, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetLevel());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.2)), 110, 2.0f);
				Font.Print("HP: ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 160, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetHP());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 160, 2.0f);
				Font.Print("MP:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 210, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetMP());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 210, 2.0f);
				Font.Print("Attack", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 260, 2.0f);
				sprintf_s(buff, "%d", (Viewing->GetAtk() + Viewing->GetWpn()));
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 260, 2.0f);
				Font.Print("Defense:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 310, 2.0f);
				sprintf_s(buff, "%d", (Viewing->GetDef() + Viewing->GetArm()));
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 310, 2.0f);
				Font.Print("Weapon:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 360, 2.0f);
				sprintf_s(buff, "%d", (Viewing->GetWpn()));
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 360, 2.0f);
				Font.Print("Armor:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 410, 2.0f);
				sprintf_s(buff, "%d", (Viewing->GetArm()));
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 410, 2.0f);
				Font.Print("Movement:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 460, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetMov());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 460, 2.0f);
				Font.Print("Press Enter To Return", 120, 530, 2.0f);
		
		}
		gameGrid->Render();
		vector<string> key = ParticleManager::GetInstance()->GetKeys();
		vector<string>::iterator iter = key.begin();
		
		CSGD_Direct3D::GetInstance()->GetSprite()->Flush();

		for(; iter != key.end(); ++iter)
		{
			if(iter->find(WS->GetKey())== 0)
			ParticleManager::GetInstance()->Render(*iter);
		}

		Tile* display = gameGrid->ReturnHilightedTile(1);

		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 12, 0, 0.7f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 12, 42, 0.7f, 1.5f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 12, 85, 0.7f, 1.5f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		switch(display->GetTerrainType())
		{
		case GRASS:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Grass", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("No Effect", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case DIRT:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Dirt", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("No Effect", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case STONE_FLOOR:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Floor", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("No Effect", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case ROCKS:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Rocks", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("No Effect", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case SNOW:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Snow", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("-1 Movement", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case MUD:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.25)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Mud", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("-25%", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				Font.Print("Atk & Def", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 95, 1.0f);
				break;
			}
		case WATER:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Water", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("-1 Move", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case SHRUB:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.25)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Shrub", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("+25%", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				Font.Print("Defense", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 95, 1.0f);
				break;
			}
		case LAVA:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.25)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Lava", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("-50%", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				Font.Print("All Stats", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 95, 1.0f);
				break;
			}
		case TREE:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Tree", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("Obstacle", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case MOUNTIAN:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Mountain", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("Obstacle", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case PILLAR:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Pillar", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("Obstacle", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case STONE_WALL:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Wall", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("Obstacle", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		case CROWD:
			{
				//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.19)),0, Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.20)};
				//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
				Font.Print("Tile Data:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 5, 1.0f);
				Font.Print("Crowd", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 35, 1.0f);
				Font.Print("Obstacle", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)), 65, 1.0f);
				break;
			}
		};

		char buffer[50];
		if(display->GetCharacter() != nullptr)
		{
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 12, 130, 0.7f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 12, 165, 0.7f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 12, 265, 0.7f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

			//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.18)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.22), Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.47)};
			//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			switch(display->GetCharacter()->GetType())
			{
			case KNIGHT:
				{
					Font.Print("Knight", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 135, 1.0f);
					break;
				}
			case ARCHER:
				{
					Font.Print("Archer", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 135, 1.0f);
					break;
				}
			case ROGUE:
				{
					Font.Print("Rogue", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 135, 1.0f);
					break;
				}
			case WIZARD:
				{
					Font.Print("Wizard", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 135, 1.0f);
					break;
				}
			case BLACK_KNIGHT:
				{
					Font.Print("Black Knight", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 135, 1.0f);
					break;
				}
			};
			Font.Print("HP: ", (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)), 165, 1.0f);
			sprintf_s(buffer, "%d", display->GetCharacter()->GetHP());
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.08)), 165, 1.0f);
			Font.Print("MP:", (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)), 195, 1.0f);
			sprintf_s(buffer, "%d", display->GetCharacter()->GetMP());
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.08)), 195, 1.0f);
			Font.Print("Damage:", (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)), 225, 1.0f);
			sprintf_s(buffer, "%d", (display->GetCharacter()->GetAtk() + display->GetCharacter()->GetWpn()));
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.05)), 225, 1.0f);
			Font.Print("Defense:", (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)), 255, 1.0f);
			sprintf_s(buffer, "%d", (display->GetCharacter()->GetDef() + display->GetCharacter()->GetArm()));
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.05)), 255, 1.0f);
		}

		TileManager * tm = TileManager::GetInstance();

		//RECT cursorRect;
		//cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
		//cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
		//cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
		//cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));
		//
		//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,255,0,0);
		//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,255,0,0);
		//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,255,0,0);
		//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,255,0,0);

		pTM->Draw(selectID, (int)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX())), (int)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY())), tm->GetScale()/2, tm->GetScale()/2, 0, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

		/*sprintf_s(buffer, "%d", Characters[1]->GetHP());
		Font.Print(buffer, (int)(Characters[1]->GetTile()->GetScreenPosX()*gameGrid->GetScale()), (int)(Characters[1]->GetTile()->GetScreenPosY()*gameGrid->GetScale()), 2.0f);

		sprintf_s(buffer, "%d", Characters[0]->GetExp());
		Font.Print(buffer, (int)(Characters[0]->GetTile()->GetScreenPosX()*gameGrid->GetScale()), (int)(Characters[0]->GetTile()->GetScreenPosY()*gameGrid->GetScale()), 1.0f);

		sprintf_s(buffer, "%d", Characters[0]->GetHP());
		Font.Print(buffer, (int)(Characters[0]->GetTile()->GetScreenPosX()*gameGrid->GetScale()) + 30, (int)(Characters[0]->GetTile()->GetScreenPosY()*gameGrid->GetScale()), 2.0f);*/

		if(GamePlayState::GetInstance()->GetDiceRolled() == true)
		{
			GamePlayState::GetInstance()->RenderDice();
		}
		if(GamePlayState::GetInstance()->GetDiceShown() == true)
		{
			GamePlayState::GetInstance()->RenderRoll();
		}

		if(Paused)
		{
			CSGD_TextureManager::GetInstance()->Draw(PanelID, 140, 30, 1.7f, 1.9f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			CSGD_TextureManager::GetInstance()->Draw(PanelID, 140, 70, 1.7f, 2.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			
			CSGD_TextureManager::GetInstance()->Draw(PanelID, 200, 150, 1.2f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			CSGD_TextureManager::GetInstance()->Draw(PanelID, 200, 190, 1.2f, 1.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			CSGD_TextureManager::GetInstance()->Draw(PanelID, 200, 225, 1.2f, 1.5f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

			Font.Print("Paused", 180, 30, 3.0f);
			Font.Print("Resume", 230, 150, 2.0f);
			Font.Print("Exit", 240, 200, 2.0f);

			RECT bottom = {0, (LONG)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.08)), (LONG)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.57)), Game::GetInstance()->GetWinHeight()};
			CSGD_Direct3D::GetInstance()->DrawRect(bottom, 0, 0, 0);
			Font.Print("Turn 0", 10, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight() * 0.07)), 1.0f);
			Font.Print("Player 1", 110, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight() * 0.07)), 1.0f);
			Font.Print("Enemy 1", 230, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight() * 0.07)), 1.0f);

			if(Resume)
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 175);
			else if(!Resume)
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 225);
		}

		if(Command && !Paused && !ItemMenu)
		{
			//RECT cmnd = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.50), Game::GetInstance()->GetWinWidth(), Game::GetInstance()->GetWinHeight()};
			//CSGD_Direct3D::GetInstance()->DrawRect(cmnd, 0, 0, 0);

			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 305, 0.8f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 346, 0.8f, 2.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 446, 0.8f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 540, 0.8f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

			Font.Print("Move", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 310, 1.0f);
			Font.Print("Attack", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 360, 1.0f);
			Font.Print("Use Ability", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 410, 1.0f);
			Font.Print("Defend", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 460, 1.0f);
			Font.Print("Use Item", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 510, 1.0f);
			Font.Print("Back", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 560, 1.0f);

			switch(CmndChoice)
			{
			case 0:
				{
					CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)), 320);
					break;
				}

			case 1:
				{
					CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)), 370);
					break;
				}

			case 2:
				{
					CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)), 420);
					break;
				}

			case 3:
				{
					CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)), 470);
					break;
				}
			
			case 4:
				{
					CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)), 520);
					break;
				}

			case 5:
				{
					CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)), 570);
					break;
				}
			};
		}

		if(ItemMenu && !Paused && !Command)
		{
			//RECT cmnd = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.50), Game::GetInstance()->GetWinWidth(), Game::GetInstance()->GetWinHeight()};
			//CSGD_Direct3D::GetInstance()->DrawRect(cmnd, 0, 0, 0);

			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 305, 0.8f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 346, 0.8f, 2.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 446, 0.8f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 2, 540, 0.8f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

			sprintf_s(buffer, "%d", HPotions);
			Font.Print("Potion ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 310, 1.0f);
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)), 310, 1.0f);
			sprintf_s(buffer, "%d", MPotions);
			Font.Print("Ether ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 360, 1.0f);
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)), 360, 1.0f);
			sprintf_s(buffer, "%d", Inhalers);
			Font.Print("Inhaler ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 410, 1.0f);
			Font.Print(buffer, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)), 410, 1.0f);
			Font.Print("Back", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)), 460, 1.0f);

			switch(ItemChoice)
			{
			case 0:
				{
					pTM->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.23)), 320);
					break;
				}

			case 1:
				{
					pTM->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.23)), 370);
					break;
				}

			case 2:
				{
					pTM->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.23)), 420);
					break;
				}

			case 3:
				{
					pTM->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.23)), 470);
					break;
				}
			};
		}

		if(abilityMenu && !ItemMenu && !Paused && !Command)
		{
			//RECT cmnd = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.27)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.50), Game::GetInstance()->GetWinWidth(), Game::GetInstance()->GetWinHeight()};
			//CSGD_Direct3D::GetInstance()->DrawRect(cmnd, 0, 0, 0);

			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 50, 305, 1.1f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 50, 346, 1.1f, 2.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 50, 446, 1.1f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 50, 540, 1.1f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

			switch (this->activeTile->GetCharacter()->GetType())
			{
			case WIZARD:
				{
					Font.Print("Lightning Bolt!!",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 310, 1.0f);
					Font.Print("Fire Ball",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 360, 1.0f);
					Font.Print("Tsunami",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 410, 1.0f);
					Font.Print("Peroxide",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 460, 1.0f);
					Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 510, 1.0f);

					break;
				}
			case KNIGHT:
				{
					Font.Print("Reinforced Armor",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 310, 1.0f);
					Font.Print("Shield Bash",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 360, 1.0f);
					Font.Print("Cover",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 410, 1.0f);
					Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 460, 1.0f);

					break;
				}

			case ARCHER:
				{
					Font.Print("Multi-Shot",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 310, 1.0f);
					Font.Print("Shoot Harder",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 360, 1.0f);
					Font.Print("Shoot Farther",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 410, 1.0f);
					Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 460, 1.0f);

					break;
				}
			case ROGUE:
				{
					Font.Print("Hide",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 310, 1.0f);
					Font.Print("Backstab",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 360, 1.0f);
					Font.Print("Inflict Allergies",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 410, 1.0f);
					Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 460, 1.0f);

					break;
				}
			case BLACK_KNIGHT:
				{
					Font.Print("Taunt",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 310, 1.0f);
					Font.Print("Bite Knee Caps",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 360, 1.0f);
					Font.Print("Guard Bridge",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 410, 1.0f);
					Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25)), 460, 1.0f);

					break;
				}
			};
			CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.27)), 320+(50*abilitySelection));

		}
			//RECT textbox = {10,(LONG)(Game::GetInstance()->GetWinHeight() * 0.85f), (LONG)(Game::GetInstance()->GetWinWidth() * .80f), (LONG)(Game::GetInstance()->GetWinHeight() * 0.95f)};
			//CSGD_Direct3D::GetInstance()->DrawRect(textbox, 0, 0, 200);

			//size_t size;
			//TCHAR buffer[128] = {};
			//mbstowcs_s(&size,buffer,128,,128);
			//for(int i = 0; i < tutConvo[currentMsg].length(); ++i)
			//{
			//	Font.Print((const char*)(&tutorConvo[currentMsg][i]), 10 /*+ (Font.GetCharWidthW() * i)*/, (int)(Game::GetInstance()->GetWinHeight() * 0.85f), 1.0f);
			//}

			pTM->Draw(PanelID, -2, 505, 3.12f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
			pTM->Draw(PanelID, -2, 540, 3.12f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		
			Font.Print(tutConvo[currentMsg].c_str(), 20 /*+ (Font.GetCharWidthW() * i)*/, (int)(Game::GetInstance()->GetWinHeight() * 0.85f), 1.0f);
		
	}
}

void TutorialPlayState::Reset(void)
{
	//for(unsigned int i = 0; i < Characters.size(); i++)
	//{
	//	delete Characters[i];
	//}
	//
	//for(unsigned int i = 0; i < Inventory.size(); i++)
	//{
	//	delete Inventory[i];
	//}
	
	//Characters.clear();
	//Inventory.clear();

	// Create Stuff
	//CreateCharacterMessage* pMsg = new CreateCharacterMessage(true, WIZARD, 2, 3);
	//CreateCharacterMessage* pMsg1 = new CreateCharacterMessage(false, KNIGHT, 2, 1);
	//MS->SendMsg(pMsg);
	//MS->SendMsg(pMsg1);
	//CreateItemMessage* pMsg2 = new CreateItemMessage(HPOTION);
	//CreateItemMessage* pMsg3 = new CreateItemMessage(HPOTION);
	//CreateItemMessage* pMsg4 = new CreateItemMessage(MPOTION);
	//MS->SendMsg(pMsg2);
	//MS->SendMsg(pMsg3);
	//MS->SendMsg(pMsg4);
	//HPotions = 2;
	//MPotions = 1;

	Tile* prevTile = Characters[0]->GetTile();

	for(int i=0; i < gameGrid->GetSizeX(); ++i)
	{
		for(int j = 0; j < gameGrid->GetSizeY(); ++j)
		{
			gameGrid->GetTile(i, j)->SetCharacter(nullptr);
		}
	}


	for(unsigned int i = 0; i < selected.size(); ++i)
		delete selected[i];

		selected.clear();

	for(unsigned int i = 0; i <  selectFrom.size(); ++i)
		delete selectFrom[i];

		selectFrom.clear();

	//for(unsigned int i = 0; i <  CharactersToTake.size(); ++i)
	//	delete CharactersToTake[i];

	CharactersToTake.clear();
	for(unsigned int i = 0; i < 8;i++)
	{
		BaseCharacter * c;
	
		switch((i/2)+1)
		{
		case KNIGHT:
			{
				c = new Knight(true);
				break;
			}
		case ARCHER:
			{
				c = new Archer(true);
				break;
			}
		case ROGUE:
			{
				c = new Rogue(true);
				break;
			}
		case WIZARD:
			{
				c = new Wizard(true);
				break;
			}
		case BLACK_KNIGHT:
			{
				c = new BlackKnight(true);
				break;
			}
	
		};
		//SizeOfParty++;
		selectFrom.push_back(c);
		//c->Release();
	}
	SizeOfParty = 0;
	SelectingCount = 0;
	prevTile->SetCharacter(nullptr);
	gameGrid->SetScale(2.0f);

	if(!tutSpawnPoint)
	{
		Characters[0]->SetTile(gameGrid->GetTile(2, 3));
		Characters[0]->SetHP(20);
		Characters[0]->SetMoved(false);
		Characters[0]->SetActed(false);
		gameGrid->GetTile(2, 3)->SetCharacter(Characters[0]);
		//Characters.clear();
		
		Characters[1]->SetTile(gameGrid->GetTile(2, 1));
		Characters[1]->SetHP(50);
		gameGrid->GetTile(2, 1)->SetCharacter(Characters[1]);
	}

	if(tutSpawnPoint)
	{
		//for(unsigned int i = 0; i < Characters.size(); ++i)
		//	delete Characters[i];

		Characters.clear();
	}

	activeTile = nullptr;

	if(tutorConvo != nullptr)
	{
		for(unsigned int i = 0; i <  tutConvo.size(); ++i)
		{
			delete[] tutorConvo[i];
		}
		delete[] tutorConvo;
		tutorConvo = nullptr;
	}

	tutConvo.clear();
	
	convo = true;
	tutMove = false;
	tutMenu = true;
	tutMove = false;
	tutAttack = false;
	tutItem = false;
	tutWeather = false;
	tutTiles = false;
	tutCharExplain = false;
	tutSpawnPoint = false;
	tutSpecialWin = false;
	tutControls = false;
	tutAbility = false;
	
	gameWon = false;
	gameWonTimer = 0;
	
	cursorX = 0;
	cursorY = 0;
	currentMsg = 0;

}

void TutorialPlayState::Exit(void)
{
	GamePlayState::GetInstance()->DeleteInstance();
	CSGD_XAudio2* XA = CSGD_XAudio2::GetInstance();

	if(tutorConvo != nullptr)
	{
		if(tutConvo.size() > 0)
		{
			for(unsigned int i = 0; i <  tutConvo.size(); ++i)
			{
				delete[] tutorConvo[i];
			}
			delete[] tutorConvo;
		}
		tutorConvo = nullptr;
	}

	//if(tutConvo.size() > 0)
	//{
	//	for(unsigned int i = 0; i< tutConvo.size(); ++i)
	//	{
	//		delete tutConvo[i];
	//	}
	//	
	//}
	

	XA->MusicStopSong(BGMID);

	if(MS != nullptr)
	{
		MS->ShutdownMsgSystem();
		MS = nullptr;
	}

	//shutdown particle manager

	ParticleManager::GetInstance()->SetKeys(keys);
	ParticleManager::GetInstance()->ShutDown();
	ParticleManager::GetInstance()->DeleteInstance();
	keys.clear();

	if(WS != nullptr)
	{
		WS->DeleteInstance();
		WS = nullptr;
	}

	// shutdown tile manager and delete the instance
	gameGrid->DestroyGrid();
	gameGrid->DeleteInstance();

	//shutdown animation manager
	if(myManager != nullptr)
	{
		myManager->ShutdownAnimationManager();
		
	}

	for(unsigned int i = 0; i < Characters.size(); i++)
	{
		delete Characters[i];
	}

	for(unsigned int i = 0; i < Inventory.size(); i++)
	{
		delete Inventory[i];
	}

	for(unsigned int i = 0; i < selectFrom.size();i++)
	{
		if(selectFrom[i] != nullptr)
		{
			delete selectFrom[i];
			selectFrom[i] = nullptr;
		}
	}
	
	selected.clear();
	selectFrom.clear();
	CharactersToTake.clear();
	Characters.clear();
	Inventory.clear();

	AIManager::GetInstance()->DeleteInstance();

	if(rhurtID != -1)
	{
		XA->SFXStopSound(rhurtID);
		XA->SFXUnloadSound(rhurtID);
		rhurtID = -1;
	}

	if(whurtID != -1)
	{
		XA->SFXStopSound(whurtID);
		XA->SFXUnloadSound(whurtID);
		whurtID = -1;
	}

	if(khurtID != -1)
	{
		XA->SFXStopSound(khurtID);
		XA->SFXUnloadSound(khurtID);
		khurtID = -1;
	}

	if(ahurtID != -1)
	{
		XA->SFXStopSound(ahurtID);
		XA->SFXUnloadSound(ahurtID);
		ahurtID = -1;
	}

	if(boltID != -1)
	{
		XA->SFXStopSound(boltID);
		XA->SFXUnloadSound(boltID);
		boltID = -1;
	}

	if(fireID != -1)
	{
		XA->SFXStopSound(fireID);
		XA->SFXUnloadSound(fireID);
		fireID = -1;
	}

	if(waterID != -1)
	{
		XA->SFXStopSound(waterID);
		XA->SFXUnloadSound(waterID);
		waterID = -1;
	}

	if(boingID != -1)
	{
		XA->SFXStopSound(boingID);
		XA->SFXUnloadSound(boingID);
		boingID = -1;
	}

	if(thudID != -1)
	{
		XA->SFXStopSound(thudID);
		XA->SFXUnloadSound(thudID);
		thudID = -1;
	}

	if(swingID != -1)
	{
		XA->SFXStopSound(swingID);
		XA->SFXUnloadSound(swingID);
		swingID = -1;
	}

	if(throwID != -1)
	{
		XA->SFXStopSound(throwID);
		XA->SFXUnloadSound(throwID);
		throwID = -1;
	}

	if(splashID != -1)
	{
		XA->SFXStopSound(splashID);
		XA->SFXUnloadSound(splashID);
		splashID = -1;
	}

	if(crackerID != -1)
	{
		XA->SFXStopSound(crackerID);
		XA->SFXUnloadSound(crackerID);
		thudID = -1;
	}

	if(tennisID != -1)
	{
		XA->SFXStopSound(tennisID);
		XA->SFXUnloadSound(tennisID);
		tennisID = -1;
	}

	if(moveID != -1)
	{
		XA->SFXStopSound(moveID);
		XA->SFXUnloadSound(moveID);
		moveID = -1;
	}
	
	if(acceptID != -1)
	{
		XA->SFXStopSound(acceptID);
		XA->SFXUnloadSound(acceptID);
		acceptID = -1;
	}
	
	if(declineID != -1)
	{
		XA->SFXStopSound(declineID);
		XA->SFXUnloadSound(declineID);
		declineID = -1;
	}
	
	if(errorID != -1)
	{
		XA->SFXStopSound(errorID);
		XA->SFXUnloadSound(errorID);
		errorID = -1;
	}
	
	if(BGMID != -1)
	{
		XA->MusicUnloadSong(BGMID);
		BGMID = -1;
	}

	if(Explosion != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(Explosion);
		Explosion = -1;
	}

	if(TennisballID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(TennisballID);
		TennisballID = -1;
	}

	if(FadeImg != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(FadeImg);
		FadeImg = -1;
	}

	if(PlungerID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(PlungerID);
		PlungerID = -1;
	}

	if(fireCrackerID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(fireCrackerID);
		fireCrackerID = -1;
	}

	if(WaterBalloonID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(WaterBalloonID);
		WaterBalloonID = -1;
	}

	if(selectID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(selectID);
		selectID = -1;
	}

	if(BackgroundID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(BackgroundID);
		BackgroundID = -1;
	}

	if(CursorID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(CursorID);
		CursorID = -1;
	}

	if(FontID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(FontID);
		FontID = -1;
	}
	if(this->tileBmpID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(tileBmpID);
		tileBmpID = -1;
	}



	MS->DeleteInstance();
	DeleteInstance();
}

// STATIC method to handle messages
void TutorialPlayState::MessageProc(BaseMessage* pMsg)
{
	TutorialPlayState* GPS = TutorialPlayState::GetInstance();

	switch(pMsg->GetID())
	{
	case MSG_CREATE_CHR:
		{
			CreateCharacterMessage* CCM = (CreateCharacterMessage*)pMsg;
			switch(CCM->GetClass())
			{
			case KNIGHT:
				{
					BaseCharacter* c = new Knight(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;

			case ROGUE:
				{
					BaseCharacter* c = new Rogue(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;

			case WIZARD:
				{
					BaseCharacter* c = new Wizard(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;

			case ARCHER:
				{
					BaseCharacter* c = new Archer(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
					break;
				}

			case BLACK_KNIGHT:
				{
					BaseCharacter* c = new BlackKnight(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;
			};
			break;
		}
	
	case MSG_WIN_TILE_EVENT:
		{
			GPS->gameWon = true;
			break;
		}

	case MSG_CREATE_ITEM:
		{
			CreateItemMessage* CIM = (CreateItemMessage*)pMsg;
			Item* i = new Item(CIM->GetItemID());
			GPS->Inventory.push_back(i);
			i = nullptr;
			delete i;
			break;
		}
	};
}

int TutorialPlayState::DiceRoll(BaseCharacter* Attacker, BaseCharacter* Defender, int wizardEnum)
{
	CurAttacker = Attacker;
	CurDefender = Defender;

	int NumRolls = 0;
	int curAttk = Attacker->GetAtk() + Attacker->GetWpn();
	
	if(wizardEnum != -1)
	{
		switch(wizardEnum)
		{
		case LIGHTNING_BOLT:
			{
				curAttk = (4 * Attacker->GetLevel()) + 8;
				AtkTypeStorage = LIGHTNING_BOLT;
				break;
			}
		case FIRE_BALLS:
			{
				curAttk = (6 * Attacker->GetLevel()) + 12;
				break;
			}
		case TSUNAMI:
			{
				curAttk = (8 * (Attacker->GetLevel()-1)) + 34;
				break;
			}
		};
	}
	
	int curDef = Defender->GetDef() + Defender->GetArm();
	vector<int> DiceRolls;
	int i = 0;
	
	if(curAttk >= 20)
	{
		NumRolls = (curAttk / 20);
		curAttk -= NumRolls*20;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(20);
		}
	}
	if(curAttk >= 12)
	{
		NumRolls =  (curAttk / 12);
		curAttk -= NumRolls*12;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(12);
		}
	}
	if(curAttk >= 10)
	{
		NumRolls =  (curAttk / 10);
		curAttk -= NumRolls*10;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(10);
		}
	}
	if(curAttk >= 8)
	{
		NumRolls =  (curAttk / 8);
		curAttk -= NumRolls*8;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(8);
		}
	}
	if(curAttk >= 6)
	{
		NumRolls =  (curAttk / 6);
		curAttk -= NumRolls*6;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(6);
		}
	}
	if(curAttk >= 4)
	{
		NumRolls = (curAttk / 4);
		curAttk -= NumRolls*4;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(4);
		}
	}
	
	int X = DiceRolls.size();
	int damage = 0;
	int Roll = 0;
	
	for(i = 0; i < X; i++)
	{
		AtkRolls.push_back(DiceRolls[i]);
		Roll = rand() % DiceRolls[i] + 1;
		ARolls.push_back(Roll);
		damage += Roll;
	}
	
	DiceRolls.clear();
	
	if(curDef >= 20)
	{
		NumRolls = (curDef / 20);
		curDef -= NumRolls*20;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(20);
		}
	}
	if(curDef >= 12)
	{
		NumRolls =  (curDef / 12);
		curDef -= NumRolls*12;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(12);
		}
	}
	if(curDef >= 10)
	{
		NumRolls =  (curDef / 10);
		curDef -= NumRolls*10;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(10);
		}
	}
	if(curDef >= 8)
	{
		NumRolls =  (curDef / 8);
		curDef -= NumRolls*8;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(8);
		}
	}
	if(curDef >= 6)
	{
		NumRolls =  (curDef / 6);
		curDef -= NumRolls*6;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(6);
		}
	}
	if(curDef >= 4)
	{
		NumRolls = (curDef / 4);
		curDef -= NumRolls*4;
	
		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(4);
		}
	}
	
	X = DiceRolls.size();
	int Defense = 0;
	
	for(i = 0; i < X; i++)
	{
		DefRolls.push_back(DiceRolls[i]);
		Roll = rand() % DiceRolls[i] + 1;
		DRolls.push_back(Roll);
		Defense += Roll;
	}
	
	damage = damage - Defense;
	if(damage <= 0)
		damage = 1;
	
	
	DiceRolled = true;
	
	return damage;


}

void TutorialPlayState::ArcadeInput()
{
	arcadeEnter = false;
	arcadeEscape = false;
	arcadeUp = false;
	arcadeDown = false;
	arcadeLeft = false;
	arcadeRight = false;
	arcadeBackspace = false;
	arcadeShift = false;
	arcadePlus = false;
	arcadeMinus = false;
	arcadeP = false;

	CSGD_DirectInput * di = CSGD_DirectInput::GetInstance();

	if(di->JoystickGetLStickDirPressed(DIR_UP,0))
	{
		arcadeUp = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_DOWN,0))
	{
		arcadeDown = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_LEFT,0))
	{
		arcadeLeft = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_RIGHT,0))
	{
		arcadeRight = true;
	}

	if(di->JoystickButtonPressed(0,0))
	{
		arcadeEnter = true;
	}

	if(di->JoystickButtonPressed(1,0))
	{
		arcadeBackspace = true;
	}

	if(di->JoystickButtonPressed(2,0))
	{
		arcadeP = true;
	}

	if(di->JoystickButtonPressed(3,0))
	{
		arcadeShift = true;
	}

	if(di->JoystickButtonPressed(4,0))
	{
		arcadePlus = true;
	}

	if(di->JoystickButtonPressed(5,0))
	{
		arcadeMinus = true;
	}

	if(di->JoystickButtonPressed(6,0))
	{
		arcadeEscape = true;
	}
}

bool TutorialPlayState::CheckMoveToTile(Tile* curTile, Tile* tar, vector<Tile*>* v)
{
	Tile * currentTile = curTile;
	Tile * target= tar;

	if(currentTile == target || target->GetObstacle() || target->GetCharacter() != nullptr)
		return false;

	int xR = 0,yR = 0,distance = 0;
	xR = currentTile->GetX() - target->GetX();
	yR = currentTile->GetY() - target->GetY();

	if(xR < 0)
		xR *= -1;
	if(yR < 0)
		yR*=-1;

	distance = xR + yR;

	if(distance > currentTile->GetCharacter()->GetMov())
		return false;
	else
	{

		int sX,sY,bX,bY;
		Tile* closestX = nullptr;
		Tile* closestY = nullptr;
		bool startX = true;

		if(currentTile->GetX() > target->GetX())
		{
			sX = target->GetX();
			bX = currentTile->GetX();
			closestX = gameGrid->GetTile(currentTile->GetX()-1,currentTile->GetY());
		}
		else
		{
			sX = currentTile->GetX();
			bX = target->GetX();
			if(currentTile->GetX() < target->GetX())
				closestX = gameGrid->GetTile(currentTile->GetX()+1,currentTile->GetY());

		}
		if(currentTile->GetY() > target->GetY())
		{
			sY = target->GetY();
			bY = currentTile->GetY();
			closestY = gameGrid->GetTile(currentTile->GetX(),currentTile->GetY()-1);

		}
		else 
		{
			sY = currentTile->GetY();
			bY = target->GetY();
			if(currentTile->GetY() < target->GetY())
				closestY = gameGrid->GetTile(currentTile->GetX(),currentTile->GetY()+1);

		}

		if(closestX != nullptr && !closestX->GetObstacle() && closestX->GetCharacter() == nullptr && closestX->GetTerrainType() != LAVA)
			startX = true;
		else if(closestY != nullptr && !closestY->GetObstacle() && closestY->GetCharacter() == nullptr && closestY->GetTerrainType() != LAVA)
			startX = false;
		else if(closestX != nullptr && !closestX->GetObstacle()&& closestX->GetCharacter() == nullptr)
			startX = true;
		else if(closestY != nullptr && !closestY->GetObstacle()&& closestY->GetCharacter() == nullptr)
			startX = false;


		if(startX && xR == 0)
			startX = false;
		else if(!startX && yR == 0)
			startX = true;

		vector<Tile*> tiles;
		tiles.clear();
		
		if(startX && closestX != nullptr)
			tiles.push_back(closestX);
		else if(!startX && closestY != nullptr)
			tiles.push_back(closestY);

		currentTile = tiles[0];

		if(currentTile->GetObstacle() || currentTile->GetCharacter() != nullptr)
		{
			tiles.clear();
			if(startX)
				tiles.push_back(closestY);
			else
				tiles.push_back(closestX);

			currentTile = tiles[0];
		}

		for(int i = 0; i < distance;i++)
		{
			Tile * nextClosestX;
			Tile * nextClosestY;

			if(currentTile == target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}

			if(tiles[i] == nullptr)
				break;

			if(sX == target->GetX())
			{
				if(tiles[i]->GetX()-1<0)
				{
					break;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()-1,tiles[i]->GetY());
			}
			else

			{

				if(tiles[i]->GetX()+1>gameGrid->GetSizeX())
				{
					break;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()+1,tiles[i]->GetY());
			}
			if(sY == target->GetY())
			{
				if(tiles[i]->GetY()-1<0)
				{
					break;
				}

				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()-1);
			}
			else
			{
				if(tiles[i]->GetY()+1>gameGrid->GetSizeY())
				{
					break;
				}
				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()+1);
			}

			if(tiles[i]->GetX() == target->GetX())
			{
				if(nextClosestY->GetObstacle() || nextClosestY->GetCharacter() != nullptr)
				{
					break;
				}
				else
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
			}
			else if(tiles[i]->GetY() == target->GetY())
			{
				if(nextClosestX->GetObstacle() || nextClosestX->GetCharacter() != nullptr)
				{
					break;
				}
				else
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
			}
			else
			{
				if(nextClosestX->GetTerrainType() != LAVA && nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetTerrainType() != LAVA && nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else if(nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else
					break;
			}

			if(currentTile = target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}

		}
		///////////////////////////////////////////////////////////////////////

		if(startX)
			startX = false;
		else
			startX = true;

		tiles.clear();
		
		if(startX)
			tiles.push_back(closestX);
		else
			tiles.push_back(closestY);

		currentTile = tiles[0];

		if(tiles[0] == nullptr)
			return false;

		if(currentTile->GetObstacle() || currentTile->GetCharacter() != nullptr)
		{
			tiles.clear();
			if(startX)
				tiles.push_back(closestY);
			else
				tiles.push_back(closestX);

			currentTile = tiles[0];
		}

		for(int i = 0; i < distance;i++)
		{
			if(tiles[i] == nullptr)
				return false;

			Tile * nextClosestX;
			Tile * nextClosestY;

			if(currentTile == target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}
			if(sX == target->GetX())
			{
				if(tiles[i]->GetX()-1<0)
				{
					return false;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()-1,tiles[i]->GetY());
			}
			else
			{
				if(tiles[i]->GetX()+1>gameGrid->GetSizeX())
				{
					return false;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()+1,tiles[i]->GetY());
			}
			if(sY == target->GetY())
			{
				if(tiles[i]->GetY()-1<0)
				{
					return false;
				}

				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()-1);
			}
			else
			{
				if(tiles[i]->GetY()+1>gameGrid->GetSizeY())
				{
					return false;
				}

				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()+1);
			}

			if(tiles[i]->GetX() == target->GetX())
			{
				if(nextClosestY->GetObstacle() || nextClosestY->GetCharacter() != nullptr)
				{
					return false;
				}
				else
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
			}
			else if(tiles[i]->GetY() == target->GetY())
			{
				if(nextClosestX->GetObstacle() || nextClosestX->GetCharacter() != nullptr)
				{
					return false;
				}
				else
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
			}
			else
			{
				if(nextClosestX->GetTerrainType() != LAVA && nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetTerrainType() != LAVA && nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else if(nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else
					return false;
			}

			if(currentTile = target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}

		}

		if(currentTile = target)
		{
			if(v != nullptr)
				(*v) = tiles;
			return true;
		}
	}
	return true;
}

void TutorialPlayState::HighlightAction(bool enemy,int range)
{
	TileManager * tm = TileManager::GetInstance();

	for(int x = 0; x < tm->GetSizeX();x++)
	{
		for(int y = 0 ; y < tm->GetSizeY();y++)
		{
			int xR = 0,yR = 0,distance = 0;
			xR = activeTile->GetX() - x;
			yR = activeTile->GetY() - y;

			if(xR < 0)
				xR *= -1;
			if(yR < 0)
				yR*=-1;

			distance = xR + yR;

			if(distance > range)
				continue;
			else
			{
				if(abilitySelection == 2 && activeTile == tm->GetTile(x,y))
					continue;

				if(tm->GetTile(x,y)->GetObstacle() || tm->GetTile(x,y)->GetCharacter() == nullptr)
					continue;
					//tm->GetTile(x,y)->HighlightTile(true,255,0,0,150);
				else
				{
					if(enemy && tm->GetTile(x,y)->GetCharacter()->IsPlayer() != activeTile->GetCharacter()->IsPlayer())
						tm->GetTile(x,y)->HighlightTile(true,0,255,0,100);
					else if(!enemy && tm->GetTile(x,y)->GetCharacter()->IsPlayer() == activeTile->GetCharacter()->IsPlayer())
						tm->GetTile(x,y)->HighlightTile(true,0,255,0,100);
				}
			}
		}
	}
}

void TutorialPlayState::HighlightMove()
{
	TileManager * tm = TileManager::GetInstance();

	if(Movement)
	{
		for(int x = 0; x < tm->GetSizeX();x++)
		{
			for(int y = 0 ; y < tm->GetSizeY();y++)
			{

				int ert;
				if(x == 2 && y == 3)
					ert = 0;


				if(!this->CheckMoveToTile(activeTile,gameGrid->GetTile(x,y)))
					continue;
					//tm->GetTile(x,y)->HighlightTile(true,255,0,0,150);
				else
					tm->GetTile(x,y)->HighlightTile(true,0,255,0,100);

				
			}
		}
	}
}

void TutorialPlayState::BattleWindowFade(void)
{
	CSGD_TextureManager::GetInstance()->Draw(FadeWindowImg, FadeWindow.left, FadeWindow.top, (float)Game::GetInstance()->GetWinWidth()/CSGD_TextureManager::GetInstance()->GetTextureWidth(FadeWindowImg), 
											 (float)Game::GetInstance()->GetWinHeight()/CSGD_TextureManager::GetInstance()->GetTextureHeight(FadeWindowImg), 
											 &FadeWindow, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(200, 255, 255, 255));

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
}

void TutorialPlayState::BattleWindow()
{
	if(CurAttacker == nullptr || CurDefender == nullptr)
		return;

	myManager->Render(CurAttacker, Game::GetInstance()->GetWinWidth()/2 - 200, Game::GetInstance()->GetWinHeight()/2 + 200, 10.0f, false);
	myManager->Render(CurDefender, Game::GetInstance()->GetWinWidth()/2 + 200, Game::GetInstance()->GetWinHeight()/2 + 200, 10.0f, true);

	vector<string>::iterator iter = ActiveKeys.begin();

	for( ; iter != ActiveKeys.end(); iter++)
	{
		if((*iter) == "FireBall.xml" || (*iter) == "TsunamiRight.xml")
		{
			if(DiceShown == true)
				ParticleManager::GetInstance()->Render((*iter));
		}
	}

	if(AtkTypeStorage != -1)
	{
		switch(AtkTypeStorage)
		{
		case LIGHTNING_BOLT:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
						CSGD_TextureManager::GetInstance()->Draw(TennisballID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 2.0f, 2.0f,
											  nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(tennisID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(throwID);
						Throw = false;
					}
					else if(playVoice && !Throw && pos>=350)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boltID);
						playVoice = false;
					}
				}
			}
			break;

		case MULTI_SHOT:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
					{
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 230, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 260, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
					}
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
						Throw = false;
					}
				}
			}
			break;

		case FIRE_BALLS:
			{
				if(DiceRolled == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2);

					if(pos <= 500)
						CSGD_TextureManager::GetInstance()->Draw(fireCrackerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2), 200, 2.0f, 2.0f,
											  nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(throwID);
						Throw = false;
					}
					else if(playVoice && !Throw && pos>=350)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(fireID);
						playVoice = false;
					}

					if(!SpellHit && !(CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(throwID)) && pos >= 375)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(crackerID);
						SpellHit = true;
					}
				}
				if(SpellHit && DiceShown == true)
					{
						if(!fbHurt)
						{
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(khurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								}
								break;
							case WIZARD:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(whurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								}
								break;
							case ARCHER:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(ahurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								}
								break;
							case ROGUE:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(rhurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								}
								break;
							};
							playVoice = false;
						}
						fbHurt = true;
					}
			}
			break;

		case TSUNAMI:
			{
				if(DiceRolled == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2);

					if(pos <= 500)
						CSGD_TextureManager::GetInstance()->Draw(WaterBalloonID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2), 200, 2.0f, 2.0f,
											  nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(throwID);
						Throw = false;
					}
					else if(playVoice && !Throw && pos>=350)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(waterID);
						playVoice = false;
					}
				}
				if(!SpellHit && DiceShown == true)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(splashID);
					SpellHit = true;
					playVoice = true;
					switch(CurDefender->GetType())
					{
					case KNIGHT:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
						break;
					case WIZARD:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
						break;
					case ARCHER:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
						break;
					case ROGUE:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
						break;
					};
					playVoice = false;
				}
			}
			break;

		case SHOOT_HARDER:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
					{
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
					}
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
						Throw = false;
					}
				}
			}
			break;

		case SHOOT_FARTHER:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
					{
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
					}
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
						Throw = false;
					}
				}
			}
			break;
		}
	}
	else
	{
		if(CurAttacker->GetType() == ARCHER)
		{
			if(DiceShown == true)
			{
				int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

				if(pos <= 500)
				{
					CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
						nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
				}
				else
				{
					if(!SpellHit)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
						SpellHit = true;
						playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
					}
				}
				if(Throw)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
					Throw = false;
				}
			}
		}
		else
		{
			if(DiceShown == true)
			{
				if(Throw)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(swingID);
					Throw = false;
				}

				if(!SpellHit && !Throw && !CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(swingID))
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
					SpellHit = true;
					playVoice = true;
					switch(CurDefender->GetType())
					{
					case KNIGHT:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
						break;
					case WIZARD:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
						break;
					case ARCHER:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
						break;
					case ROGUE:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
						break;
					};
					playVoice = false;
				}
			}
		}
	}
}
